I have iframe where I have several charts and gridviews where the charts and gridviews are fetching data from database.when records found no issue but for some users don't have records for one of gridviews where I have to display a message "No records found".
kindly suggest me on this. I tried the below code which displays a message but it displays in small box,but I need to display inside the gridview.
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EmptyDataTemplate>No records Found</EmptyDataTemplate>
Here I am not showing grid header,but i have to!
To do that, we need to enable the Boolean property ShowHeaderWhenEmpty to True. Be sure you're using the ASP.NET 4.0 or later version to use this property. Also, we need to add the <EmptyDataTemplate></EmptyDataTemplate> property inside the grid view to display the message.
The initial bind of an "empty" row will make the headers show and then the row being hidden will make it appear like an empty grid view. Show activity on this post. GridView1. DataSourceID = null; GridView1.
The work around is to ensure that a dummy row is returned from the database when there is no real data present. You need to ensure that you have set the ShowFooter property of GridView to true. Another option to show header when GridView is empty is to set the GridView. ShowHeaderWhenEmpty property to true.
Start by adding a GridView to your web page. To make the columns sortable, you need to set the GridView's property AllowSorting = “true” and OnSorting = “OnSorting”. SortExpression property will hold the name of the column you want to sort.
Set ShowHeaderWhenEmpty
property on the GridView to true
.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.showheaderwhenempty.aspx
But you still have to DataBind the gridview. This code snippet worked for me:
<asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
<Columns>
<asp:boundfield datafield="CustomerID" headertext="Customer ID"/>
<asp:boundfield datafield="Name" headertext="Name"/>
</Columns>
</asp:GridView>
try setting emptydatatext
and ShowHeaderWhenEmpty
<asp:gridview id="GridView"
datasourceid="DataSource"
autogeneratecolumns="true"
emptydatatext="No data in the data source."
runat="server"
ShowHeaderWhenEmpty="True">
</asp:gridview>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With