开发者

asp.net gridview paging

开发者 https://www.devze.com 2023-01-14 02:33 出处:网络
I have a grid view which has 10 rows. I have set paging = true and pageSize = 2 Now when I try to navigate through the page by the below mentioned link like 1, 2, 3

I have a grid view which has 10 rows. I have set paging = true and pageSize = 2

Now when I try to navigate through the page by the below mentioned link like 1, 2, 3 , I then receive error something like need event pageIndexChanged.

I added this event but do not understand what code should I add to this event to navigate t开发者_开发知识库o next page by maintain the state in each page ?

Please let me know


All you need to do is set the PageIndex for the GridView to the new page, and re-bind the control.

protected void gridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  gridView1.PageIndex = e.NewPageIndex;
  BindGrid(); // this is whatever method you call to bind your data.
}

EDIT:

You should already have an event-handler for the DataBound event of the GridView:

protected void GridView1_DataBound(object sender, EventArgs e)
{
    // lots of code here to do stuff with bound data.
}

Instead of having "lots of code", you have this:

protected void GridView1_DataBound(object sender, EventArgs e)
{
   BindGrid();
}

Therefore on the PageIndexChanging event, all you're doing is re-binding the data (calling the same logic for the DataBound event).

Make sense?

0

精彩评论

暂无评论...
验证码 换一张
取 消