Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)aaa
published in(发表于) 2013/12/11 8:29:42
ASP.NET组件DataGrid的分页实用方法_.net资料_编程技术

ASP.NET组件DataGrid的分页实用方法_.net资料_编程技术-你的首页-uuhomepage.com

  查了网上资料,关于这个DataGrid分页实在是太多太多方法,有些解决方法过于Trick,有些则效率较低,这里提供一个不太麻烦,也效率尚可(通过Session缓存DataSet)的方法:


  拖动DataGrid到WebForms,从DataGrid的属性栏中选择Columns打开DataGrid Properties自定义对话框,选择Paging分页,Allow paging, Page size: 20。


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!this.IsPostBack)
{
sqlDataAdapter1.Fill(dataSet11);
Session["CopyYear"]=dataSet11;
DataGrid1.DataSource = dataSet11.Tables[0].DefaultView;
DataGrid1.DataBind();
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
dataSet11=(DataSet1)Session["CopyYear"];
DataGrid1.DataSource = dataSet11.Tables[0].DefaultView;
DataGrid1.DataBind();
}


  在页面上添加上述代码,OK






If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759