I have this code on a gridview
<asp:GridView ID="ReconcileGridView" runat="server" EmptyDataText="Please Select Transaction Month And Date" AutoGenerateSelectButton="True"
BackColor="White" BorderColor="#4A3C8C" BorderWidth="3px" GridLines="Both" BorderStyle="Solid"
CellPadding="3" AllowPaging="True" OnPageIndexChanging="ReconcileGridView_PageIndexChanging"
OnRowDataBound="ReconcileGridView_RowDataBound" OnSelectedIndexChanged="ReconcileGridView_SelectedIndexChanged">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<EmptyDataTemplate>
<center>
No Record Found
</center>
</EmptyDataTemplate>
</asp:GridView>
The Problem is on page Load i want the word Please Select Transaction Month And Date to appear and when a user inputs the a transaction month and date and no data was retrieved
No Record Found should show, how would i do that? on the code above only the word No Record Found shows, i Databind Empty Data on page load to make those messages appear.
please help on making that happen.
You have to place a separate Label control for word Please Select Transaction Month And Date
and on page load, you have to set the label control visible property true
and when user inputs the month and date then you can set the lable control property false.
make sense?
You have to place a separate Label control for "Please Select Transaction Month And Date" and on page load, you have to set the label control visible property true and when user inputs the month and date then you can set the label control property false.
Make sure not to bind your Gridview in the page load.
If you are placing the Gridview in an update panel and binding to null to clear it, then the EmptyDataTemplate will be shown. You most likely want to label to shown and not the EmptyDataTemplate. So you will need to hide the entire GridView (if not displaying headers) or you will need to add a cssClass to hide the EmptyDataTemplate at the appropriate points in the codebehind (alternatively use javascript).
Related
I've been utilizing what I call, "drag, drop and configure" programming for years to create very simple ASP.net forms to collect data for my organization. Basically, I'll drag a datasource into my design view, configure it, and then I'll drag a gridview into the design view and then configure it, etc., etc.
Yesterday, I encountered a behavior I have never seen. My gridview is set to allow row selection. Everything seemed to be working normally until I happened to click on a row that didn't "select" (didn't highlight itself, etc.). And, then I started clicking on other rows and found more that couldn't be selected. Again -- it's not all the rows...just some. i.e. some can be selected and others can't.
After a lot of troubleshooting, the only thing I've been able to determine is that above a certain datakey value -- rows won't select. In this case, its datakeys with values around and > 40,000. Anything below that, and the rows select and the other parts of the form load just fine. The fact that it works for all records with datakeys below a certain value is really stumping me as to what rock to look under next -- hence, actually creating a stackoverflow account and posing the question.
Code for the gridview is below. It does live within an update panel if that matters. Also provided the code behind, though it's not really doing anything of consequence.
Note:
The datakey that seems to be controlling the behavior is a unique identifier for an application within a set of applications. It's not an incremental identity. --- if that helps.
The form is hooked into a database for the select statement and is pulling records from a view to populate the grid.
I'm tempted to show all of my code including the database side and stored procs -- thinking maybe I'm making rookie mistakes with data typing, etc. --- BUT --- I'm pausing there because the gridview selection IS WORKING -- just not above datakeys around and above 40,000
Lastly, when you attempt to select an item with a key > 40,000 the grid will no longer sort by columns or allow you to click a different page. Similarly, if you sort the grid FIRST by applicationID (the datakey) -- all the pages with datakeys > 40,000 are not clickable i.e. pagination for those pages do not work
EDIT --- DANG IT!!! I posted the wrong code behind. I replaced it with the right one. UPDATE: It looks like it's related to the panels. When I comment them out --- it works. When they are included -- the rows in question (keys > 40000) aren't selectable. All this code does is control visibility of panels. How could visibility properties make this kind of impact....weird
Pic of Issue:
<ContentTemplate>
<strong>
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
Select AIT by using search box below or by sorting and paging through AIT table.<br />
<br />
Search: </strong> <asp:TextBox ID="TxtAITSearch" runat="server"></asp:TextBox>
<asp:Button ID="btn_Search" runat="server" OnClick="btn_Search_Click" Text="Search" />
<em>
<br />
*wildcard searches for AIT number, AIT Name or AIT Manager may be used</em><asp:HiddenField ID="hdnApl_ID" runat="server" />
<asp:HiddenField ID="hdn_StandardID" runat="server" />
<asp:HiddenField ID="Hdn_AlignmentID" runat="server" />
<asp:HiddenField ID="hdn_Attribute" runat="server" />
<br />
<asp:GridView ID="gvAITSelect" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="applicationID" DataSourceID="DSGetSearchView" GridLines="Vertical" OnSelectedIndexChanged="gvAITSelect_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="applicationID" HeaderText="App ID" SortExpression="applicationID" />
<asp:BoundField DataField="fullName" HeaderText="Application" SortExpression="fullName" />
<asp:BoundField DataField="Alignment" HeaderText="Alignment" SortExpression="Alignment" />
<asp:BoundField DataField="AlignmentID" HeaderText="AlignmentID" SortExpression="AlignmentID" Visible="False" />
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
<asp:BoundField DataField="relatedAssociates_2_displayName" HeaderText="App Mgr" SortExpression="relatedAssociates_2_displayName" />
<asp:BoundField DataField="relatedAssociates_3_displayName" HeaderText="Tech Exec" SortExpression="relatedAssociates_3_displayName" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
protected void gvAITSelect_SelectedIndexChanged(object sender, EventArgs e)
{
lbl_Alignment.Text = gvAITSelect.SelectedRow.Cells[3].Text;
Hdn_AlignmentID.Value = gvAITSelect.SelectedRow.Cells[4].Text;
string strAITvalue = gvAITSelect.SelectedRow.Cells[1].Text;
hdnApl_ID.Value = strAITvalue.ToString();
//panel_RoleDetails.Visible = true;
//panel_AITAlignment.Visible = true;
//panel_NoteDetails.Visible = true;
}
Ok -- I figured it out. And, the answer is, I'm a big dummy. Further, the fact that the grid stopped working around in and around 40000 should have been a big flashlight to me pointing the way. Pic of the issues
If you look at the pic I uploaded -- in the course of troubleshooting an earlier and unrelated issue -- I set the DbType (highlighted row) to Int16. In the available selections I don't see an unsigned Int16 -- so, this appears to be signed---Annnnnnnnnnnnnnnnd, of course, good developers know Int16s hold values up to 32,767. Guess what happened when I changed it back to the default "Object"? Yup. It worked. So the problem not at all weird or strange. Instead, very much a rookie mistake.
All this said -- good learning experience. Additionally, #Albert D. Kallal and #fnostro you both gave me some good understanding on some things for the future. I appreciate both of you trying to help me. And, now I also, have a stackoverflow account :)
Thanks again.
I have a grid view populated using a stored procedure. I want to implement filtering to some columns using a drop-down list. Normally i will have 4 drop down lists for 4 columns to filter.
What I tried is:
Created a stored procedure to populate unique values for the dropdown list
I added the event onselected index change to the dropdown so as when the value change the gridview is repopulated based on the value selected but the event is not triggered here
Both my gridview and dropdown list is found inside an update panel which normally will prevent postback. I added a trigger bind to dropdown list control but nothing happens.
Can you advice please how to proceed and if there is any other more efficient way for this scenario please?
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="dptest"
OnSelectedIndexChanged="dptest_OnSelectedIndexChanged" />
<asp:GridView ID="testID" runat="server" CellPadding="3"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
<FooterStyle BackColor="White" ForeColor="#000066"/>
<HeaderStyle Width="100px" BackColor="#006699" Font-Bold="True" ForeColor="White"/>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left"/>
<RowStyle Width="100px" ForeColor="#000066"/>
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White"/>
<SortedAscendingCellStyle BackColor="#F1F1F1"/>
<SortedAscendingHeaderStyle BackColor="#007DBB"/>
<SortedDescendingCellStyle BackColor="#CAC9C9"/>
<SortedDescendingHeaderStyle BackColor="#00547E"/>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
```
I only needed to add AutoPostBack="True" for the drop-down list and it worked perfectly.
I have a DataGrid that displays notes for a customer form. So if something in the form gets changed a note is created saying what changes where made. Right now the newest notes gets put to the bottom of the list. But how do I switch that around so the newest notes are at the top?
<div id="tabNotesComments" runat="server">
<div>
Notes/Comments for the customer
<asp:DataGrid CssClass="tblResults" runat="server" ID="dgNotes" OnItemDataBound="dgNotes_ItemDataBound" DataKeyField="ID" AutoGenerateColumns="false">
<HeaderStyle CssClass="tblResultsHeader" />
<AlternatingItemStyle BackColor="#EEEEEE" />
<Columns>
<asp:BoundColumn DataField="Note" HeaderText="Note"></asp:BoundColumn>
<asp:BoundColumn DataField="CreatedBy" HeaderText="Entered By"></asp:BoundColumn>
<asp:BoundColumn DataField="DateString" HeaderText="Date"></asp:BoundColumn>
<asp:BoundColumn DataField="TimeString" HeaderText="Time"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
</div>
You can see in the image what I mean. See how the most recent note is at the bottom. I want to display this list in reverse so the newest notes are displayed first.
Code for binding DataGrid:
dgNotes.DataSource = c.NotesList;
dgNotes.DataBind();
Answer
Thanks for Dimitris Batsougiannis's answer I used reverse:
dgNotes.DataSource = c.NotesList;
c.NotesList.Reverse();
dgNotes.DataBind();
Have you tried using the Reverse method ?
As the title suggests, I am attempting to set the UpdateMehod of a GridView to false. When the Update buttons is currently clicked, the event fires validation of a separate control, even though the separate control is in a separate validation group. The grid view is shown below:
<asp:GridView ID="BikesItems"
runat="server"
CssClass="table table-hover"
ItemType="WLL.DAL.Bike"
DataKeyNames="BikeID"
SelectMethod="BikesItems_GetData"
UpdateMethod="BikesItems_UpdateItem"
DeleteMethod="BikesItems_DeleteItem"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
AutoGenerateColumns="false"
ValidationGroup="BikeGrid">
<Columns>
<asp:DynamicField DataField="BikeID" />
<asp:DynamicField DataField="BikeName" />
<asp:DynamicField DataField="Description" />
<asp:DynamicField DataField="ImgPath" />
<asp:DynamicField DataField="Price" />
<asp:DynamicField DataField="ManufacturerID" />
</Columns>
</asp:GridView>
How do I set the CausesValidation to false for the update button, bearing in mind it is dynamically generated? Or does a more elegant solution exist? Thanks
If you just wish to disable the validation group in the code behind (server-side), Use Page.GetValidators("ValidationGroup") method. You can pass in the name of the ValidationGroup and the method returns a ValidatorCollection over which you can iterate.
Or ClientSide, you can iterate over the Page_Validators array and check each validator group name that matches the group you're looking for and disable each as needed.
i have to fix the header in a gridview and i use this in style Class
<style type="text/css">
.gridFixedHeader
{
background-color:white;
position:relative;
top:expression(GridView1.offsetParent.scrollTop-2);
}
</style>
but i get an error that expression(GridView1.offsetParent.scrollTop-2);is not valid...
what all do i need to do to make this work.....
any suggestions
Main aim... to fix the headers so they dont move when the gridview is scrolled up or down...
any help will be appreciated...
here is my gridview code
<asp:Panel ID="Panel1" runat="server" Height="100px" ScrollBars="Vertical">
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataKeyNames="MachineGroupID" DataSourceID="SqlDataSource1">
<RowStyle ForeColor="#000066" />
<HeaderStyle CssClass="gridFixedHeader" />
<Columns>
<asp:BoundField DataField="MachineGroupID" HeaderText="MachineGroupID"
InsertVisible="False" ReadOnly="True" SortExpression="MachineGroupID" />
<asp:BoundField DataField="MachineGroupName" HeaderText="MachineGroupName"
SortExpression="MachineGroupName" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</asp:Panel>
so here i have a gridview where when i scroll the header row moves too.. i dont want that to happen..
It is not valid in W3C. It is an IE only thing. To do what you are looking for in a valid way would require you to run some JavaScript and fix your headers.
If you explain your desired outcome I am sure someone can help. I have made GridView headers look exactly like I want many times.
UPDATE: Here is a good article: http://www.dotnetcurry.com/ShowArticle.aspx?ID=255
When the gridview is rendered to html, the GridView1 ID is probably being rewritten.
you probably want something like:
top:expression(<%= GridView1.ClientID %>.offsetParent.scrollTop-2);
although this may get you what you want it's probably not the best form.
You are heavily advised against using CSS expressions, as they get executed on every event of the browser - including mouseMove. They also don't work on anything but IE.
I can't answer your question further due to lack of details of what you're trying to achieve.
If you're trying to fix it to the top of the viewport try:
.gridFixedHeader
{
background-color:white;
position:fixed;
top:20px; //optional
}
in the elements CSS
edit: just realised you look like you're styling a GridViews header so this will probably not work, try posting some of the Gridview generated HTML and what yo want done with it please