早教吧 育儿知识 作业答案 考试题库 百科 知识分享

datalist实现分页出问题,publicpartialclassDefault2:System.Web.UI.Page{StudentBusinesssb=newStudentBusiness();PagedDataSourcepds=newPagedDataSource();protectedvoidPageLoad(objectsender,EventArgse){ifthis.Page.IsPostBack){pds.Cu

题目详情
datalist实现分页出问题,
public partial class Default2 :System.Web.UI.Page
{
StudentBusiness sb = new StudentBusiness();
PagedDataSource pds = new PagedDataSource();
protected void Page_Load(object sender,EventArgs e)
{
if this.Page.IsPostBack)
{
pds.CurrentPageIndex = 0;
pds.AllowPaging = true;
pds.PageSize = 3;
dlBind();
}
}
public void dlBind()
{
DataSet ds = sb.GetStudentInfo();
pds.DataSource = ds.Tables[0].DefaultView;
DataList1.DataSource = pds;
DataList1.DataBind();
this.lblTotalCount.Text = ds.Tables[0].Rows.Count.ToString();
btnFirst.Enabled = pds.IsFirstPage;//显示第一页时“首页”按钮不可用
btnPrevious.Enabled = pds.IsFirstPage;//显示第一页时“上一页”按钮不可用
btnNext.Enabled = pds.IsLastPage;//显示最后一页时“下一页”按钮不可用
btnLast.Enabled = pds.IsLastPage;//显示最后一页时“尾页”按钮不可用
lblCurrentPage.Text = Convert.ToString(pds.CurrentPageIndex+1);
lblCountPage.Text = pds.PageCount.ToString();
lblCurrentPageIndex.Text = pds.CurrentPageIndex.ToString();
}
protected void btnFirst_Click(object sender,EventArgs e)
{
pds.CurrentPageIndex = 0;
dlBind();
}
protected void btnPrevious_Click(object sender,EventArgs e)
{
pds.CurrentPageIndex = pds.CurrentPageIndex - 1;
dlBind();
}
protected void btnNext_Click(object sender,EventArgs e)
{
pds.CurrentPageIndex = pds.CurrentPageIndex +1;
dlBind();
}
protected void btnLast_Click(object sender,EventArgs e)
{
pds.CurrentPageIndex = pds.PageCount - 1;
dlBind();
}
}
现在首次加载一切正常,点击"下一页"按钮数据全出现没分页,
▼优质解答
答案和解析
下一页后blCurrentPageIndex 和lblCountPage显示正常吗?
看了 datalist实现分页出问...的网友还看了以下: