datalist加了分页代码后, 自定义数据时,如何按条件显示?代码是什么?比如datalist显示id=1的数据
3个回答
展开全部
分页中不是有获取数据库信息吗?而其中的SQL语句就是按条件查询的数据字符串
简单的来说,之前是将查询的数据直接绑定到datalist上,而现在是将数据绑定到分页的对象上,其对象赋值给datalist
简单的来说,之前是将查询的数据直接绑定到datalist上,而现在是将数据绑定到分页的对象上,其对象赋值给datalist
追问
具体的代码是什么?
追答
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
ps.DataSource = ContentBO.GetData(Department, Physician, Disease).DefaultView;
ps.PageSize = 5;
ps.AllowPaging = true;
if (ViewState["PageIndex"] != null)
ps.CurrentPageIndex = Convert.ToInt32(ViewState["PageIndex"].ToString());
else
{
ViewState["PageIndex"] = 0;
ps.CurrentPageIndex = Convert.ToInt32(ViewState["PageIndex"].ToString());
}
if (ps.CurrentPageIndex == 0)
{
lbFirstPage.Enabled = false;
lbPreviousPage.Enabled = false;
}
else
{
lbFirstPage.Enabled = true;
lbPreviousPage.Enabled = true;
}
endPage = ps.PageCount;
if (ps.CurrentPageIndex == endPage - 1)
{
lbNextPage.Enabled = false;
lbLastPage.Enabled = false;
}
else
{
lbNextPage.Enabled = true;
lbLastPage.Enabled = true;
}
int RecoredCount = ContentBO.GetData(Department, Physician, Disease).Rows.Count;
if (RecoredCount <= 0)
{
this.PageSplit.Visible = false;
this.divMsg.Visible = true;
}
else
{
this.PageSplit.Visible = true;
this.divMsg.Visible = false;
}
lblCurrentPage.Text = "第"+(ps.CurrentPageIndex+1).ToString()+"页/";
lblTotalPage.Text = "共"+endPage.ToString()+"页";
dltData.DataSource = ps;
dltData.DataBind();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询