好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

asp.net中的GridView分页问题

本文实例讲述了asp.net中的GridView分页问题。分享给大家供大家参考。具体分析如下:

在ASP.NET中,经常会使用到GridView的分页,一般情况下,若使用Visual Studio自带的数据源控件,不会出现什么问题。
但是如果自己用代码设置GridView的数据源,GridView中第一页显示正常,这时如果点击第二页,则经常会出现如下错误
提示:GridView“GridView_test”激发了未处理的事件“PageIndexChanging”。

这个问题的解决方法是:

1、在GridView的.aspx设计页面中,添加

复制代码 代码如下:

AllowPaging="true"

以及

复制代码 代码如下:

OnPageIndexChanging="GridView_test_PageIndexChanging";



复制代码 代码如下:

<asp:GridView ID="GridView_module" runat="server"  AllowPaging="true"  OnPageIndexChanging="GridView_test_PageIndexChanging" >

2、在.aspx.cs页面中,添加如下代码:

复制代码 代码如下:

protected void GridView_test_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{
     GridView_test_PageIndex = e.NewPageIndex;         
     GridView_test.DataSource="**";//设置数据源        
     GridView_test.DataBind();
}

 

3、运行程序,翻页时就不会出错了。

希望本文所述对大家的asp.net程序设计有所帮助。

查看更多关于asp.net中的GridView分页问题的详细内容...

  阅读:55次