Asp.Net里面DataList分页 代码问题 10
///<summary>///分页绑定///</summary>privatevoidDataListDataBind(){PagedDataSourcepd=newPa...
/// <summary>
/// 分页绑定
/// </summary>
private void DataListDataBind()
{
PagedDataSource pd = new PagedDataSource();
List<chanpin> list = null;
if (Session["erjiId"] != null)
{
ShangPinBLL shangpin = new ShangPinBLL();
list = shangpin.GetChanPinByErJiLeiIdFenYe(Convert.ToInt32(Session["erjiId"]));
}
if (Session["sanjiId"] != null)
{
ShangPinBLL shangpin = new ShangPinBLL();
list = shangpin.GetChanPinBySanJiLeiIdFenYe(Convert.ToInt32(Session["sanjiId"]));
}
pd.DataSource = list;
pd.AllowPaging = true;
pd.PageSize = 2;
Getout(pd);
pd.CurrentPageIndex = pageIndex;
this.pageCount = pd.PageCount;
this.DataListQitashangpin.DataSource = pd;
this.DataListQitashangpin.DataBind();
//合计信息
string pageInfo = "共" + pd.PageCount + "页";
lblyeshu.Text = pageInfo;
}
public void Getout(PagedDataSource pd)
{
LinkBntshangyiye.Enabled = true;
LinkBntxiayiye.Enabled = true;
if (pd.IsFirstPage)
{
LinkBntshangyiye.Enabled = false;
}
else if (pd.IsLastPage)
{
LinkBntxiayiye.Enabled = false;
}
}
//设置当前页面
private int pageIndex
{
set
{
ViewState["page"] = value;
}
get
{
if (ViewState["page"] == null)
{
ViewState["page"] = 0;
}
return Convert.ToInt32(ViewState["page"]);
}
}
//设置页面属性:存储总页数
private int pageCount
{
get
{
if (ViewState["count"] == null)
{
ViewState["count"] = 0;
}
return Convert.ToInt32(ViewState["count"]);
}
set
{
ViewState["count"] = value;
}
}
//分页....上一页
protected void LinkBntshangyiye_Click(object sender, EventArgs e)
{
this.pageIndex--;
DataListDataBind();
}
//分页....下一页
protected void LinkBntxiayiye_Click(object sender, EventArgs e)
{
this.pageIndex++;
DataListDataBind();
}
分页是分了,为什么点上一页,下一页没反应。 展开
/// 分页绑定
/// </summary>
private void DataListDataBind()
{
PagedDataSource pd = new PagedDataSource();
List<chanpin> list = null;
if (Session["erjiId"] != null)
{
ShangPinBLL shangpin = new ShangPinBLL();
list = shangpin.GetChanPinByErJiLeiIdFenYe(Convert.ToInt32(Session["erjiId"]));
}
if (Session["sanjiId"] != null)
{
ShangPinBLL shangpin = new ShangPinBLL();
list = shangpin.GetChanPinBySanJiLeiIdFenYe(Convert.ToInt32(Session["sanjiId"]));
}
pd.DataSource = list;
pd.AllowPaging = true;
pd.PageSize = 2;
Getout(pd);
pd.CurrentPageIndex = pageIndex;
this.pageCount = pd.PageCount;
this.DataListQitashangpin.DataSource = pd;
this.DataListQitashangpin.DataBind();
//合计信息
string pageInfo = "共" + pd.PageCount + "页";
lblyeshu.Text = pageInfo;
}
public void Getout(PagedDataSource pd)
{
LinkBntshangyiye.Enabled = true;
LinkBntxiayiye.Enabled = true;
if (pd.IsFirstPage)
{
LinkBntshangyiye.Enabled = false;
}
else if (pd.IsLastPage)
{
LinkBntxiayiye.Enabled = false;
}
}
//设置当前页面
private int pageIndex
{
set
{
ViewState["page"] = value;
}
get
{
if (ViewState["page"] == null)
{
ViewState["page"] = 0;
}
return Convert.ToInt32(ViewState["page"]);
}
}
//设置页面属性:存储总页数
private int pageCount
{
get
{
if (ViewState["count"] == null)
{
ViewState["count"] = 0;
}
return Convert.ToInt32(ViewState["count"]);
}
set
{
ViewState["count"] = value;
}
}
//分页....上一页
protected void LinkBntshangyiye_Click(object sender, EventArgs e)
{
this.pageIndex--;
DataListDataBind();
}
//分页....下一页
protected void LinkBntxiayiye_Click(object sender, EventArgs e)
{
this.pageIndex++;
DataListDataBind();
}
分页是分了,为什么点上一页,下一页没反应。 展开
3个回答
展开全部
当然没反映了,你每次触发事件的时候pageIndex的值已经没有了,所以你要解决的就是你要怎样去传递你的pageIndex的值.
你可以把pageindex做成视图状态来进行保存,比如:
public int PageIndex
{
set { this.ViewState["CurrentPageIndex"] = value; }
get
{
int index = 0;
object obj = this.ViewState["CurrentPageIndex"];
// 可能没有赋职为NULL
if (obj != null)
{
index = (int)obj;
}
return index;
}
}
视图状态会影响网页的速度,不要过多的使用...
你可以把pageindex做成视图状态来进行保存,比如:
public int PageIndex
{
set { this.ViewState["CurrentPageIndex"] = value; }
get
{
int index = 0;
object obj = this.ViewState["CurrentPageIndex"];
// 可能没有赋职为NULL
if (obj != null)
{
index = (int)obj;
}
return index;
}
}
视图状态会影响网页的速度,不要过多的使用...
展开全部
看看这个,有详细的datalist分页介绍
http://zhidao.baidu.com/question/98224755.html
http://zhidao.baidu.com/question/98224755.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是不是你的datalist没有绑定ID啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询