Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid vs GridView - not acting the same if empty

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
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:

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
 
I've never had to do something like this, but take a look at the EmptyDataText and EmpltyDataRowStyle properties of the gridview. Perhaps they may help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top