Reputation: 1123
I have a grid as follows
<asp:GridView ID="gvFgOrder" runat="server" AutoGenerateColumns="false">
<EmptyDataTemplate>
<thead>
<tr>
<th>Order ID</th>
<th>Total Price</th>
</tr>
<tr>
<td colspan="2" style="text-align: center">No records found</td>
</tr>
</thead>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="Order ID" DataField="OrderID" />
<asp:BoundField HeaderText="Total Price" DataField="TotalPrice" />
</Columns>
</asp:GridView>
When the data source is not null the data is sown in <table><tbody>
as expected
Whenever the data source is null the empty template is rendered. But the problem is an empty row is added in <tbody>
tag as
<table>
<thead>
<tr>
<td>Order ID</td>
<td>Total Price</td>
</tr>
<tr>
<td colspan="2">No records found</td>
</tr>
</thead>
<tbody>
<tr><td></td><tr>
</tbody>
</table>
How can eliminate this table row from tbody. I have attached a click listener to <tbody>
<tr>
So unwanted care is required in javascript.
How can I get around this?
Is this the proper way of using a <EmptyDataTemplate>
?
My Aim is to show as follows when datasource is empty
Upvotes: 1
Views: 2331
Reputation: 1123
Finally I have found the solution
Adding the line
<EmptyDataRowStyle CssClass="hide" />
Saved my day. This causes the extra tbody tr to be hidden when data source is null.
Upvotes: 0
Reputation: 28417
That is because you are adding that into a thead
. Hence regular tbody
is also being generated albeit empty.
Just specify the row:
<EmptyDataTemplate>
<tr>
<td colspan="2" style="text-align: center">No records found</td>
</tr>
</EmptyDataTemplate>
You could also use EmptyDataText
<GridView ... EmptyDataText="[ No details available... ]" >
Upvotes: 0
Reputation: 31
I would suggest you to use a div inside the emptydatatemplate instead of thead and tr tags.
Upvotes: 1