GridView Blank with AllowPaging="True"

J

Jonathan Wood

Okay, I spent about 3 hours getting the GridView control to do what I
needed.

Basically, I set the control's AutoGenerateColumns to False and then defined
a single template column (which I will customize with my own content). This
looks something like this:

<asp:GridView ID="GridView1" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
Width="100%" AllowPaging="False"
OnPageIndexChanged="GridView1_PageIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Articles">
<ItemTemplate>
<b><%# Eval("art_name") %></b><br />
<%# Eval("art_desc") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Then, in my page's Load event, I run a database query and do something like
this:

SqlDataReader reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();

I finally got it working. However, when I set the AllowPaging property to
True, then the grid displays absolutely nothing on the Web page. (It looks
fine in the IDE.)

I even tried running a new query and re-executing the lines above in
response to the control's PageIndexChanged event but that doesn't help.

Does anyone have any ideas?

Thanks!
 
E

Eliyahu Goldin

Jonathan,

I guess the problem is in using a SqlDataReader as a datasource. The msdn
library states that "the paging feature can be used with any data source
object that supports the System.Collections.ICollection interface or a data
source that supports paging capability". SqlDataReader is neither of them.
An example of a data source that supports paging capability is
SqlDataSource.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
M

Mark Rae

I finally got it working. However, when I set the AllowPaging property to
True, then the grid displays absolutely nothing on the Web page. (It looks
fine in the IDE.)

I even tried running a new query and re-executing the lines above in
response to the control's PageIndexChanged event but that doesn't help.

Does anyone have any ideas?

You're using an SqlDataReader as the DataSource - can't do that if you want
paging.

Use a DataSet instead and all will be well.
 
J

Jonathan Wood

That must be it. Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Eliyahu Goldin said:
Jonathan,

I guess the problem is in using a SqlDataReader as a datasource. The msdn
library states that "the paging feature can be used with any data source
object that supports the System.Collections.ICollection interface or a
data source that supports paging capability". SqlDataReader is neither of
them. An example of a data source that supports paging capability is
SqlDataSource.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jonathan Wood said:
Okay, I spent about 3 hours getting the GridView control to do what I
needed.

Basically, I set the control's AutoGenerateColumns to False and then
defined a single template column (which I will customize with my own
content). This looks something like this:

<asp:GridView ID="GridView1" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
Width="100%" AllowPaging="False"
OnPageIndexChanged="GridView1_PageIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Articles">
<ItemTemplate>
<b><%# Eval("art_name") %></b><br />
<%# Eval("art_desc") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Then, in my page's Load event, I run a database query and do something
like this:

SqlDataReader reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();

I finally got it working. However, when I set the AllowPaging property to
True, then the grid displays absolutely nothing on the Web page. (It
looks fine in the IDE.)

I even tried running a new query and re-executing the lines above in
response to the control's PageIndexChanged event but that doesn't help.

Does anyone have any ideas?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top