Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2008

Tip: Looking for answers? Try searching our database.

Paging to the next page always gives me the first page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cmrchs@gmail.com - 23 Jul 2008 16:30 GMT
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
Patrice - 23 Jul 2008 16:42 GMT
Do you rebind your date to the grid on each postback ?

<cmrchs@gmail.com> a écrit dans le message de groupe de discussion :
0021d58e-0cc4-4e11-93e5-246a9cf4adf3@x41g2000hsb.googlegroups.com...
> Hello,
>
[quoted text clipped - 9 lines]
> thank you
> Chris
Christian Cambier - 23 Jul 2008 18:15 GMT
> Do you rebind your date to the grid on each postback ?
>
[quoted text clipped - 14 lines]
> > thank you
> > Chris

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
Patrice - 23 Jul 2008 18:30 GMT
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" <christian.cambier@gmail.com> a écrit dans le message de
groupe de discussion :
adf8b794-b90f-4813-90dd-a69d95ce05be@l64g2000hse.googlegroups.com...
>> Do you rebind your date to the grid on each postback ?
>>
[quoted text clipped - 32 lines]
> thank you
> Chris
Christian Cambier - 23 Jul 2008 18:43 GMT
> 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.
[quoted text clipped - 55 lines]
> > thank you
> > Chris

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
Patrice - 23 Jul 2008 19:17 GMT
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
cmrchs@gmail.com - 23 Jul 2008 19:30 GMT
> 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
[quoted text clipped - 20 lines]
> --
> Patrice

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
cmrchs@gmail.com - 23 Jul 2008 19:42 GMT
On Jul 23, 8:30 pm, cmr...@gmail.com wrote:

> > 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
[quoted text clipped - 31 lines]
> 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
Patrice - 24 Jul 2008 09:10 GMT
> I don't have any problems with the GridView.
> it's just that, I am preparing a course and in order to explain
[quoted text clipped - 6 lines]
> best regards
> Chris

Hummm.. your previous sample uses a SqlDataSource, not a SqlDataAdapter ???
The sample code you provided will work with only the two changes I mentioned
(i.e. using a GridView and DataBind is not even needed).

Now is this some other code that you would like to make work. I'm a bit
confused...  In all cases using  a GridView will IMO be more likely easier
and closest to what your students could have to use...
--
Patrice
cmrchs@gmail.com - 23 Jul 2008 19:41 GMT
> 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
[quoted text clipped - 20 lines]
> --
> Patrice

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.