查了网上资料,关于这个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
http://www.cnblogs.com/ericguo/archive/2006/11/21/practice_datagrid_page.html