AspNetPager 翻页不重新绑定dropdownlist

bychgh 2010-10-19 10:04:52
用的AspNetPager 分页控件
用dropdownlist来查询绑定repeat
当翻页的时候,dropdownlist就重新绑定数值,默认第一项来取值重新绑定repeat了,怎么在翻页的时候,比如选dropdownlist第二项,翻页的时候,还是根据第二项来查?



protected void Page_Load(object sender, EventArgs e)
{

if (!this.IsPostBack)
{
this.SetNewListPage();
bindcity();
}


}
private void bindcity()
{
this.ddl_city.DataSource = zphcity.GetAllList();
this.ddl_city.DataTextField = "city_name";
this.ddl_city.DataValueField = "city_id";
this.ddl_city.DataBind();
}

protected void SetNewListPage()
{
int count = 0;
this.rp_list.DataSource = com_bll.GetList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, "id", false, "cid=" + cid, out count);
this.rp_list.DataBind();

this.AspNetPager1.RecordCount = count;
AspNetPager1.CustomInfoHTML = "<font color='#000'>记录总数:</font><font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + " </b></font>";
AspNetPager1.CustomInfoHTML += "<font color='#000'>总页数:</font><font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + " </b></font>";
AspNetPager1.CustomInfoHTML += "<font color='#000'>当前页:</font><font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + " </b></font>";

}


protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
this.SetNewListPage();
}

protected void btn_query_Click(object sender, EventArgs e)
{
cid = this.ddl_city.SelectedItem.Value;
this.SetNewListPage();
}

...全文
188 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookyzlr 2010-10-19
  • 打赏
  • 举报
回复
哦不对,复制到Setnewpagelist函数中更好些
bychgh 2010-10-19
  • 打赏
  • 举报
回复
改了之后就好了
bychgh 2010-10-19
  • 打赏
  • 举报
回复
UrlPaging="false" 之前是true
hookyzlr 2010-10-19
  • 打赏
  • 举报
回复
将cid赋值的那句话复制到Aspnetpager_changded事件中去。应该就不会出现这个问题了。
MSDNXGH 2010-10-19
  • 打赏
  • 举报
回复
那个分页控件,有一个分页事件,你在分页事件那儿再重新绑定。。。
记得在poad事件中的绑定要放在if(!IsPostBack)这个条件下。这样回发事就不会再绑定,减少负担
flyerwing 2010-10-19
  • 打赏
  • 举报
回复
没太明白!
重新绑定就好了
ddlstselectindex_change(object sender,eventargs e)
{
anp.currentpageindex=Convert.toint(this.ddlst.selectitems.value);
}
好象成吧
bychgh 2010-10-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wyq29 的回复:]
cid是全局变量?

你的代码不会产生你说的问题啊。。。

翻页并不会影响 ddl_city 选择值。。。
[/Quote]

cid 是申明的全局变量
wyq29 2010-10-19
  • 打赏
  • 举报
回复
cid是全局变量?

你的代码不会产生你说的问题啊。。。

翻页并不会影响 ddl_city 选择值。。。
bychgh 2010-10-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sprc_lcl 的回复:]
this.rp_list.DataSource = com_bll.GetList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, "id", false, "cid=" + this.ddl_city.SelectedValue, out count);
[/Quote]
不行
sprc_lcl 2010-10-19
  • 打赏
  • 举报
回复
this.rp_list.DataSource = com_bll.GetList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, "id", false, "cid=" + this.ddl_city.SelectedValue, out count);

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧