Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GridView not Showing Headers When there are No Rows

3 views
Skip to first unread message

Steve Harclerode

unread,
May 14, 2008, 7:04:36 PM5/14/08
to
Hi,

I'm trying to get my DataGrid to show headers and footers when no rows are
returned from the datasource. Below is code that shows the first
TemplateField. Is there an easy way to get at least the footer to show? I
want to be able to insert a new row using the footer. Thanks...

<asp:GridView ID="gvMaterials" runat="server"
AutoGenerateColumns="False"
DataSourceID="dsMaterials" ShowFooter="True" Width="100%"
AutoGenerateEditButton="True">
<Columns>
<asp:TemplateField HeaderText="Material:">
<FooterTemplate>
<asp:TextBox ID="txtDescription"
runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDescription" runat="server"
Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%#
Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
[etc...]

--
My BizTalk blog:
http://stevestechnotes.blogspot.com/


Marc Gravell

unread,
May 15, 2008, 3:30:39 AM5/15/08
to
What is the actual data-source - i.e. the object you give to
dsMaterials?

I'm going to go out on a limb and guess that it is an ArrayList?

To get metadata, it needs some clue to the data. There are various
ways it can do this - the simplest is a typed indexer - i.e. a "public
T this[int index] {get;}" for some T (doesn't have to be generics...).

In the absense of a typed indexer, the metadata of the first item is
used. If there aren't any items, you're scuppered.

(there are also things like ITypedList and IListSource that are taken
into account, but these are more complex)

Marc Gravell

unread,
May 15, 2008, 3:31:51 AM5/15/08
to
Oops; I forgot to say! If you are using an ArrayList, the easiest way
to fix this is to use a List<T> or BindingList<T>, or perhaps even
just an array: T[]

If you aren't using ArrayList, then tell us what you *are* using as
the data-source.

Marc

Steve Harclerode

unread,
May 15, 2008, 1:45:49 PM5/15/08
to
I'm using a SqlDataSource that calls a stored procedure -- which contains a
simple "SELECT * FROM Tablex WHERE ...".

Thanks,
Steve

"Marc Gravell" <marc.g...@gmail.com> wrote in message
news:decd1a39-6c12-4a55...@x35g2000hsb.googlegroups.com...

Marc Gravell

unread,
May 16, 2008, 3:35:21 AM5/16/08
to
Hmmm... I would have expected to work. I'm sorry, but I don't know. If
you don't get any other takers, I would recommend posting on an asp
group, since there will be many GridView experts there...

Marc

sunillakshkar

unread,
May 19, 2008, 1:30:29 AM5/19/08
to
HI Steve,

Gridview does not display anything if database is returning zero number of rows.
In case you still want to display it then you can enter some dummy rows in an arraylist or dataset and then connect it to gridview and then hide that dummy row in grid , it will display only header and footer now.

Steve Harclerode

unread,
May 19, 2008, 2:54:02 PM5/19/08
to
Thanks for your input, Sunil. I'll try that.

- Steve

<Sunil Lakshkar> wrote in message news:20085191302...@gmail.com...

0 new messages