asp.net gridview的分页 [英] asp.net gridview paging

查看:270
本文介绍了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).

请有意义吗?

这篇关于asp.net gridview的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆