Paging error.

B

Ben Smith

I am relatively new to all of this and I am encountering a annoying problem.
I have a datagrid of data that I want to page through. I am using numeric
pages and can ascend the pages 1,2,3, etc fine. Its when I get to the last
page, which has fewer items that all of the rest.

As soon as I hit the last page, let's say, page 3 in this example, is when I
run into the problem. Pages 1 and 2 have 6 items and page 3 only has 3.
When I click to go to page 1 or 2 while viewing page 3, the two things I'd
expect it to do, it doesn't. Instead of going to the page I clicked, it
goes back to the beginning and the page navigation still says that I am on
the last page.

Any ideas? Am I being clear?

Thanks in advance.

Ben
 
J

Jeffrey Tan[MSFT]

Hi Ben,

Thank you for posting in the community!

Based on my understanding, you use datagrid to do data paging. But while
you view the 3rd page(Last page), if you click the 1 or 2 page, your paging
will not navigate to that page, but rest on the 3rd page.

===============================================
Do you use normal datagrid paging or custom paging?

I think you did not provide enough information for your issue. Can you
explain the more detailed reproduce steps or code?

Actually, I have writen a sample paging project using Sql server's default
database for you, please do like this:
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private DataSet ds;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
getsource();
databinding();
}
}

private void getsource()
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from
orders","server=localhost;database=northwind;uid=sa;pwd=");
ds=new DataSet();
adapter.Fill(ds);
}

private void databinding()
{
DataGrid1.DataSource =ds.Tables[0];
DataGrid1.DataBind();
}

private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
getsource();
databinding();
}

When you view different pages through page navigation bar, if you want to
maintain your page view's scroll position(Not always go to the top of the
page), you can set the Page.SmartNavigation Property to true. (In the
property browser's combobox choose "document", then change its
smartnavigation property)

====================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Ben Smith

I think this will work. This is a much clearer example than what I've been
able to find.

Thank you!

Ben
 
J

Jeffrey Tan[MSFT]

Hi Ben,

Thanks very much for your feedback.

I am glad my reply makes sense to you.

If you have any further concern, please feel free to tell me, I am glad to
work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top