I have an ASP.NET GridView that uses an EmptyDataTemplate. This template is used to collect data in the event that no records exist in my data source. My GridView source looks like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="Lecturer" CellPadding="4"
ForeColor="#333333" GridLines="None" style="text-align: center" allowsorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
<asp:HyperLinkField HeaderText="URL" SortExpression="url" DataNavigateUrlFields="url" Text="Link" ItemStyle-Width="100" />
</Columns>
<EmptyDataTemplate>
No data found!
</EmptyDataTemplate>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
The problem here is that i want the empty data template to be shown after the button search has been click but right now everytime i open the page, it will show the empty data template eventhough i didnt do any searching yet.
use:
EmptyDataText="No data found!"
in a grid like:
<asp:GridView ID="GridView1" EmptyDataText="No data found!" ....>
Your way is incorrect.EmptyDataTemplate isn't use for this purpose.
Remove EmptyDataTemplate, when you search if no records match with the search, set EmptyDataText of your 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