主题:DataList分页后显示不完整
我在datalist的项板中放了一个表格分页显示,数据库库中有26条记录,每页放10条记录,数据成功绑定,分页也成功了,但是26条数据应改显示3页呀,我的程序只分了2页,而且只取出了数据库中ID为1-20的数据,还有6条没有取出来是什么原因呀?
ICollection CreateSource()
{
int StartIndex;
StartIndex=CurrentPage*PageSize;
string strsql="select * from Message order by ID desc";
SqlConnection conn=new SqlConnection (ConfigurationSettings.AppSettings["ConnString"]);
conn.Open();
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strsql,conn);
da.Fill(ds,StartIndex,PageSize,"Message");
return ds.Tables["Message"].DefaultView;
}
//数据绑定
public void DataListBind()
{
this.DataList1.DataSource=CreateSource();
this.DataBind();
}
//分页
public void Page_OnClick(object sender,CommandEventArgs e)
{
CurrentPage=(int)ViewState["PageIndex"];
PageCount=(int)ViewState["PageCount"];
string cmd=e.CommandName;
switch(cmd)
{
case "Next":
if(CurrentPage<PageCount-1)
{
CurrentPage+=1;
}
break;
case "Prev":
if(CurrentPage>0)
{
CurrentPage--;
}
break;
case "Lst":
CurrentPage=PageCount-1;
break;
default:
CurrentPage=0;
break;
}
ViewState["PageIndex"]=CurrentPage;
DataListBind();
}
ICollection CreateSource()
{
int StartIndex;
StartIndex=CurrentPage*PageSize;
string strsql="select * from Message order by ID desc";
SqlConnection conn=new SqlConnection (ConfigurationSettings.AppSettings["ConnString"]);
conn.Open();
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strsql,conn);
da.Fill(ds,StartIndex,PageSize,"Message");
return ds.Tables["Message"].DefaultView;
}
//数据绑定
public void DataListBind()
{
this.DataList1.DataSource=CreateSource();
this.DataBind();
}
//分页
public void Page_OnClick(object sender,CommandEventArgs e)
{
CurrentPage=(int)ViewState["PageIndex"];
PageCount=(int)ViewState["PageCount"];
string cmd=e.CommandName;
switch(cmd)
{
case "Next":
if(CurrentPage<PageCount-1)
{
CurrentPage+=1;
}
break;
case "Prev":
if(CurrentPage>0)
{
CurrentPage--;
}
break;
case "Lst":
CurrentPage=PageCount-1;
break;
default:
CurrentPage=0;
break;
}
ViewState["PageIndex"]=CurrentPage;
DataListBind();
}