.net datalist借助 PagedDataSource实现分页的问题
数据源sqldatasource1和控件datalist1已经设置好并在页面正常显示了内容现在想实现分页page_load里的代码如下:PagedDataSourcepd...
数据源sqldatasource1和控件datalist1已经设置好 并在页面正常显示了内容 现在想实现分页 page_load里的代码如下:
PagedDataSource pds = new PagedDataSource();
pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
pds.AllowPaging = true;
pds.PageSize = 24;
pds.CurrentPageIndex = 0;
DataList1.DataSource = pds;
DataList1.DataBind();
然后 把datalist1 属性中 的DataSourceID="SqlDataSource1 也删除了 但还是显示的全部内容 没有实现分页 我想问下 问题出在哪 请高手指点下 展开
PagedDataSource pds = new PagedDataSource();
pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
pds.AllowPaging = true;
pds.PageSize = 24;
pds.CurrentPageIndex = 0;
DataList1.DataSource = pds;
DataList1.DataBind();
然后 把datalist1 属性中 的DataSourceID="SqlDataSource1 也删除了 但还是显示的全部内容 没有实现分页 我想问下 问题出在哪 请高手指点下 展开
1个回答
展开全部
仔细看了LZ的提问,没看出什么问题
===========下面我是使用的方法,希望对你有帮助
不过一般都是用分页控件来实现的
【首页】【上一页】【下一页】【尾页】
DataTable dt=数据
if (dt.Rows.Count > 0)
{
labcount.Text = dt.Rows.Count.ToString();
PagedDataSource ps = new PagedDataSource();
ps.DataSource = dt.DefaultView;
ps.AllowPaging = true;
ps.PageSize = 20;
int pagecount = ps.PageCount;
int curpage = Convert.ToInt32(this.txbcurrpage.Text.Trim());
this.labpagecount.Text = pagecount.ToString();
this.lkbnext.Enabled = true;
this.lkbfirst.Enabled = true;
this.lkbprev.Enabled = true;
this.lkbend.Enabled = true;
if (curpage == 1)
{
this.lkbfirst.Enabled = false;
this.lkbprev.Enabled = false;
}
if (curpage == pagecount)
{
this.lkbnext.Enabled = false;
this.lkbend.Enabled = false;
}
ps.CurrentPageIndex = curpage - 1;
this.replist.DataSource = ps;
this.replist.DataBind();
}
else
{
this.labpagecount.Text = "1";
labcount.Text = "0";
this.lkbfirst.Enabled = false;
this.lkbprev.Enabled = false;
this.lkbnext.Enabled = false;
}
===========下面我是使用的方法,希望对你有帮助
不过一般都是用分页控件来实现的
【首页】【上一页】【下一页】【尾页】
DataTable dt=数据
if (dt.Rows.Count > 0)
{
labcount.Text = dt.Rows.Count.ToString();
PagedDataSource ps = new PagedDataSource();
ps.DataSource = dt.DefaultView;
ps.AllowPaging = true;
ps.PageSize = 20;
int pagecount = ps.PageCount;
int curpage = Convert.ToInt32(this.txbcurrpage.Text.Trim());
this.labpagecount.Text = pagecount.ToString();
this.lkbnext.Enabled = true;
this.lkbfirst.Enabled = true;
this.lkbprev.Enabled = true;
this.lkbend.Enabled = true;
if (curpage == 1)
{
this.lkbfirst.Enabled = false;
this.lkbprev.Enabled = false;
}
if (curpage == pagecount)
{
this.lkbnext.Enabled = false;
this.lkbend.Enabled = false;
}
ps.CurrentPageIndex = curpage - 1;
this.replist.DataSource = ps;
this.replist.DataBind();
}
else
{
this.labpagecount.Text = "1";
labcount.Text = "0";
this.lkbfirst.Enabled = false;
this.lkbprev.Enabled = false;
this.lkbnext.Enabled = false;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询