您的位置:首页 > 其它

DataGrid实现自定义分页

2006-07-01 09:54 281 查看
把DataGrid的AllowPaging和AllowCustomPaging 都设置为true;

private const int PAGE_SIZE = 5; //每页5个记录

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

if ( !IsPostBack )
{
int recordCount = 0;
DataGrid1.DataSource = GetData( 0 , PAGE_SIZE , ref recordCount); //得到记录数
DataGrid1.PageSize = PAGE_SIZE;

//不能直接给pagecount赋值,因为它是只读的,VirtualItemCount / PageSize 就是页数。
DataGrid1.VirtualItemCount = recordCount;
DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataBind();
}

}

private void gridOrder_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.DataSource = GetData( e.NewPageIndex , PAGE_SIZE , ref recordCount); //得到记录数

// 设置当前的Page序号值
DataGrid1.CurrentPageIndex =e.NewPageIndex;

DataGrid1.DataBind();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐