檢視了網路資料,關於這個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