Paging to the next page always gives me the first page

C

cmrchs

Hello,

I have set the Allowpaging property to true in a standard DataGrid-
control (System.Web.UI.WebControls).

when run in the browser i get the first records in the first page,
there are 5 pagesi n total, but when I click on the next page number,
I always get the records of the first page ?

how come?

thank you
Chris
 
C

Christian Cambier

Do you rebind your date to the grid on each postback ?

hello,

Is that what you mean?

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataGrid1.DataBind();
}
}
but i still get the problem.

what do you suggest?

thank you
Chris
 
C

Christian Cambier

Let's restart fresh. This is not the expected behavior and we can't really
guess what you have done wrong without seeing some code.

I would suggest to simplify your code as much as possible even possibly
providing a fictionous code constructed datatable as a data source and show
us the code around 20 lignes of code should be enough to reproduce this
problem.

My guess was that the data are binded on each postback to the grid causing
the paging mechanism to be reset. But it seems this is not what you were
doing (my suggestion was about what the problem is, not how it should be
fixed, sorry for being unclear)...

How do you bind those data ? Do you do this only on the first run or on each
postback ?

--
Patrice

"Christian Cambier" <[email protected]> a écrit dans le message de
groupe de discussion :
(e-mail address removed)...

thank you for your time!

here's what i\ve done.

In design mode: I drag a datagrid control on the webform. I configure
the datasource using the wizard that appears so I specify:
the data connection , the sql-select statement and that's it.

the code generated in my webform1.aspx is:

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="CSharpWebApp.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True"
DataSourceID="SqlDataSource1">
</asp:DataGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>
</form>
</body>
</html>

and added in the code behind-file:
protected void Page_Load(object sender, EventArgs e)
{
//if (! IsPostBack)
DataGrid1.DataBind();
}

it doesn't work, with or without the commented line
only the first records are shown.

any ideas?

Chris
 
C

cmrchs

Sorry. I just noticed you are really using a DataGrid ? Are you still using
.NET 1.1 ? 2.0 I would say as you are using a SqlDataSource which is likely
new also in 2.0.

The DataGrid is AFAIK here mainly for legacy support. I would strongly
suggest to use a GridView instead. If you can then :
- replace your DataGrid control with a GridView.
- suppress the DataBind call, this is done for you when using a GridView
control

and paging should work wihtout any other change !!!

IMO the problem is that the DataGrid is AFAIK here mainly for legacy support
and perhaps doesn't support all the features against the newer data sources
(not sure but I believe we had to code for handling sorting and perhaps in
some cases paging depending on the datasource, this is doen automatically in
most if not all cases when using a GridView). I'm afraid that if you need to
keep using a DataGrid control you'll have to implement custom code to handle
paging.

Is using a GridView acceptable ?

I don't have any problems with the GridView.
it's just that, I am preparing a course and in order to explain
ADO.NET in detail, for me things can be explained more clearly using
the DatGrid and SqlDataAdapter as I have done in the past.

I guess I'll have to find another way to explain it.

than you again for your time
best regards
Chris
 
C

cmrchs

Sorry. I just noticed you are really using a DataGrid ? Are you still using
.NET 1.1 ? 2.0 I would say as you are using a SqlDataSource which is likely
new also in 2.0.

The DataGrid is AFAIK here mainly for legacy support. I would strongly
suggest to use a GridView instead. If you can then :
- replace your DataGrid control with a GridView.
- suppress the DataBind call, this is done for you when using a GridView
control

and paging should work wihtout any other change !!!

IMO the problem is that the DataGrid is AFAIK here mainly for legacy support
and perhaps doesn't support all the features against the newer data sources
(not sure but I believe we had to code for handling sorting and perhaps in
some cases paging depending on the datasource, this is doen automatically in
most if not all cases when using a GridView). I'm afraid that if you need to
keep using a DataGrid control you'll have to implement custom code to handle
paging.

Is using a GridView acceptable ?


Patrice,

is it still possible to use the sqlDataAdapter, 'cause adding it to
the toolbox doesn't work (see post in this newsgroup "can not add the
SqlDataAdapter to the toolbox ???")

'cause without it i don't see how i can use the DataSet in the new
method, with the GridView and SqlDataSource-control

thank you
Chris
 
C

cmrchs

I don't have any problems with the GridView.
it's just that, I am preparing a course and in order to explain
ADO.NET in detail, for me things can be explained more clearly using
the DatGrid and SqlDataAdapter as I have done in the past.

I guess I'll have to find another way to explain it.

than you again for your time
best regards
Chris


Patrice,

is it still possible to use the sqlDataAdapter, 'cause adding it to
the toolbox doesn't work (see post in this newsgroup "can not add the
SqlDataAdapter to the toolbox ???")

'cause without it i don't see how i can use the DataSet in the new
method, with the GridView and SqlDataSource-control

thank you
Chris
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top