关于DataGrid自动分页的不能显示的问题

来源:互联网 发布:在淘宝开网店 物流 编辑:程序博客网 时间:2024/05/16 19:48

关于DataGrid自动分页的问题
在属性生成器中设置DataGrid自动分页后并没有完全结束,这是因为它会在页面中只显示第一页。当点击下一页时页面刷新后竟然还显示第一页。这不是IsPostBack的问题,而是没有写分页代码的问题。
DataGrid自动分页后需要写入分页代码。分页代码要改变CurrentPageIndex为e.NewPageIndex。

我得一段代码为
 private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
 {
  SqlConnection myConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
  SqlDataAdapter myCommand = new  SqlDataAdapter("select * FROM View_QuestionTable", myConnection);
  DataSet ds = new DataSet();
  myCommand.Fill(ds, "View_QuestionTable");
  DataGrid1.DataSource = ds.Tables["View_QuestionTable"].DefaultView;
  DataGrid1.CurrentPageIndex=e.NewPageIndex;  
  DataGrid1.DataBind();
 }

网友:
<
WebForm中的DataGrid要实现分页,除了把AllowPaging设为true外,还必须为PageIndexChanged事件编写事件处理程序,在该程序中把DataGrid的CurrentPageIndex设为DataGridPageChangedEventArgs参数的NewPageIndex值,然后重新绑定数据。用这种方法分页,如果要分页的数据非常大的话,速度会很慢,用存储过程和我写的这个免费分页控件可以大大提高分页速度,有兴趣的话可以从这里下载aspNetPager:http://www.webdiyer.com
>

参阅:
http://topic.csdn.net/t/20041122/20/3578017.html
WinForm中的DataGrid的确需要编写相应的代码才能实现分页,这个网页中的内容也许能帮助你.  
http://www.cnblogs.com/icesnaker/archive/2004/07/31/29017.aspx

原创粉丝点击