Paging Datagrid - Prev / Next will not appear as links

D

Darren

Dear Groups

I've used paging with a datagrid in C# at least a hundred times, but
for whatever reason, I cannot get the prev /next to appear as links.
It is absolutely certain that the number of records exceed the page
size.

Code is as follows:

<asp:datagrid id="grdStores" runat="server" allowpaging="True"
autogeneratecolumns="False" allowcustompaging="True"">
<alternatingitemstyle backcolor="#F0F1F3"></alternatingitemstyle>
<itemstyle cssclass="grdrow"></itemstyle>
<headerstyle cssclass="grdheader"></headerstyle>
<columns>
<asp:boundcolumn datafield="Name" headertext="Store Name">
<itemstyle width="25%"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="Address" headertext="Store Address">
<itemstyle width="50%"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="City" headertext="City">
<itemstyle width="20%"></itemstyle>
</asp:boundcolumn>
<asp:templatecolumn>
<headerstyle cssclass="grdheader"></headerstyle>
<itemstyle width="15px"></itemstyle>
<itemtemplate>
<asp:linkbutton id="lnkEdit" commandname="Edit" commandargument='<%#
DataBinder.Eval(Container.DataItem, "storeid" ) %>'
runat=server>Edit</asp:linkbutton>
</itemtemplate>
</asp:templatecolumn>
</columns>
<pagerstyle nextpagetext="Next" prevpagetext="Prev"></pagerstyle>
</asp:datagrid>

Databinding


SqlConnection connLC;
SqlCommand cmd;
SqlDataReader dtrCombos;
connLC = new
SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
connLC.Open();
string cSql="Select * from stores order by Name";
cmd = new SqlCommand(cSql , connLC);
dtrCombos = cmd.ExecuteReader();
if (dtrCombos.Read())
{
dtrCombos.Close();
dtrCombos = cmd.ExecuteReader();
grdStores.DataSource=dtrCombos;
grdStores.DataBind();
}
dtrCombos.Close();
connLC.Close();

Thanks in advance,

Darren
 
T

Teemu Keiski

As you have custom paging enabled (allowcustompaging="true"), you should
tell the exact row count for the grid via VirtualItemCount property. Another
thing being that paging with a datareader can get difficult.
 
D

Darren

Thanks for your assistance everyone. Absolutely, using the datareader
in this scenario was problematic. I switched to a dataset and problem
solved. Thanks again.

Darren
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top