asp.net中datagrid分页代码,和属性设置

来源:百度知道 编辑:UC知道 时间:2024/05/10 21:40:48
我在datagrid属性里设置了启用分页后,但书预览得时候还是不能分页,请问分页代码应该怎么写,datagrid应该怎样设置?请留下全部源码!谢谢

数据填充
private void DataShow()
{
SqlConnection conn=new SqlConnection(Globals.ConnStr);
conn.Open();
string sqls="SELECT * FROM MyQQCount";
SqlCommand comm=new SqlCommand(sqls,conn);
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=comm;
DataSet ds=new DataSet();
sda.Fill(ds,"NewTable");
this.DataGrid1.DataSource=ds.Tables["NewTable"];
this.DataGrid1.DataBind();
}
分页事件
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataShow();

}

当然此分页效率很差, 建议用AspNetPager 之类的分页控件.

不但要AllowPaging="True",还要PageSize="10"