468,272 Members | 2,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

GridView Blank with AllowPaging="True"

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!

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jan 29 '07 #1
4 6721
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" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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!

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


Jan 29 '07 #2
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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.
Jan 29 '07 #3
That must be it. Thanks.

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

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uO**************@TK2MSFTNGP04.phx.gbl...
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" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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!

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



Jan 29 '07 #4
I'll look into using a DataSet instead.

Thanks.

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

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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.

Jan 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by nick chan | last post: by
reply views Thread by hhoang.nl | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.