asp.net gridview的分页
我有其中有10行的网格视图。我已设置分页= TRUE
和的pageSize = 2
I have a grid view which has 10 rows. I have set paging = true
and pageSize = 2
现在,当我尝试像1下面提到的链接,2,3通过页面浏览
,然后我收到错误类似事件需要 pageIndexChanged
。
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
.
我添加了这个事件,但不明白code,我应该加入到这个活动导航到下一个页面在每个页面维护状态?
I added this event but do not understand what code should I add to this event to navigate to next page by maintain the state in each page ?
请让我知道
所有你需要做的是设置的PageIndex为GridView到新页面,并控制重新绑定。
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.
}
编辑:
您应该已经有一个事件处理程序为GridView的DataBound事件:
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.
}
相反有大量的code的,你有这样的:
Instead of having "lots of code", you have this:
protected void GridView1_DataBound(object sender, EventArgs e)
{
BindGrid();
}
因此在PageIndexChanging事件,你正在做的是重新绑定数据(呼吁DataBound事件相同的逻辑)。
Therefore on the PageIndexChanging event, all you're doing is re-binding the data (calling the same logic for the DataBound event).
请有意义吗?