现在的位置: 首页 > 综合 > 正文

DataGrid中自带的分页功能的使用

2013年10月11日 ⁄ 综合 ⁄ 共 521字 ⁄ 字号 评论关闭

1、把AllowPaging属性设置为true   并设置PageSize的大小

2、在html页面中设置datagrid的属性OnPageIndexChanged="DataGrid_Page" //

//DataGrid_Page 为点击页数的时候激发的事件 

3、在程序中加入代码如下:

  public void DataGrid_Page(object sender,DataGridPageChangedEventArgs e)
  {
   DataGrid1.CurrentPageIndex=e.NewPageIndex;
   BindData();  //绑定数据的方法  自己写   还有记得在Page_Load中调用BindData()方法的时候不要放  在if(Is_PostBack)里面!
  }

4、当你需要多次调用的时候同时每次都是初始化显示第一页记得在Page_Load中设置

      DataGrid1.CurrentPageIndex = 0;

      否则它会默认显示上一次显示的页数,可能会导致错误出现,因为这次显示的页数可能跟本没有 上次的多。

5、ok

6 、If you have some good ideas ,pls contact to me!

抱歉!评论已关闭.