查了網上資料,關於這個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