471,357 Members | 1,090 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

GridView not Showing Headers When there are No Rows

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/
Jun 27 '08 #1
6 4351
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)
Jun 27 '08 #2
Oops; I forgot to say! If you are using an ArrayList, the easiest way
to fix this is to use a List<Tor 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
Jun 27 '08 #3
I'm using a SqlDataSource that calls a stored procedure -- which contains a
simple "SELECT * FROM Tablex WHERE ...".

Thanks,
Steve

"Marc Gravell" <ma**********@gmail.comwrote in message
news:de**********************************@x35g2000 hsb.googlegroups.com...
What is the actual data-source - i.e. the object you give to
dsMaterials?

Jun 27 '08 #4
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
Jun 27 '08 #5
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.
Jun 27 '08 #6
Thanks for your input, Sunil. I'll try that.

- Steve

<Sunil Lakshkarwrote in message news:20*********************@gmail.com...
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.

Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by tshad | last post: by
4 posts views Thread by Marcos Beccar Varela | GamaCom Argentina | last post: by
2 posts views Thread by Flinky Wisty Pomm | last post: by
reply views Thread by Innova | last post: by
4 posts views Thread by Tomasz Jastrzebski | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.