I am changing my DataGrid to a GridView but I need the Grid to display even if the DataBind doesn't return any rows.
The databind should return a list of answers.
The last row is the Footer and is for adding a new answer.
If nothing is returned, a DataGrid will still display the header and allow me to enter a new answer in the Footer.
But a GridView doesn't seem to show anything. No Header and no Footer - so I can't add my first answer.
Both GridView and DataGrid are virtually identical in my case:
GridView:
Is there a way to get the GridView to display even when empty?
Thanks,
Tom
The databind should return a list of answers.
The last row is the Footer and is for adding a new answer.
If nothing is returned, a DataGrid will still display the header and allow me to enter a new answer in the Footer.
But a GridView doesn't seem to show anything. No Header and no Footer - so I can't add my first answer.
Both GridView and DataGrid are virtually identical in my case:
Code:
<asp:DataGrid visible="true"
border="1"
id="DataGrid1"
runat="server"
AutoGenerateColumns="False"
CssClass="testsDatagrid"
gridlines="both"
ShowFooter="true"
style="margin:0">
<AlternatingItemStyle CssClass="testsDatagridAlternate"></AlternatingItemStyle>
<HeaderStyle CssClass="testsDatagridHeader"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" columns="60" MaxLength="250" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" columns="60" MaxLength="250" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
GridView:
Code:
<asp:GridView visible="true"
border="1"
id="GridView1"
runat="server"
AutoGenerateColumns="False"
CssClass="testsDatagrid"
gridlines="both"
ShowFooter="true"
style="margin:0">
<AlternatingRowStyle CssClass="testsDatagridAlternate"/>
<HeaderStyle CssClass="testsDatagridHeader"/>
<Columns>
<asp:TemplateField HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" columns="60" MaxLength="250" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" columns="60" MaxLength="250" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Is there a way to get the GridView to display even when empty?
Thanks,
Tom