一个页面有3个栏目,没个栏目都有一个AspNetPager,逐步调试,每点一次分页,后台都执行3次绑定,求达人帮忙优化一下。

z8129858 2010-11-01 02:44:51
下面是绑定方法和事件
public void bind_default()
{
if (!string.IsNullOrEmpty(Request.QueryString["year"]))
{
if (Request.QueryString["year"].ToString().Equals("2010"))
{
AspNetPager1.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
AspNetPager2.CurrentPageIndex = 1;
AspNetPager3.CurrentPageIndex = 1;
}
else if (Request.QueryString["year"].ToString().Equals("2009"))
{
AspNetPager1.CurrentPageIndex = 1;
AspNetPager2.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
AspNetPager3.CurrentPageIndex = 1;
}
else if (Request.QueryString["year"].ToString().Equals("2008"))
{
AspNetPager1.CurrentPageIndex = 1;
AspNetPager2.CurrentPageIndex = 1;
AspNetPager3.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
}
string tablelist = " sell_2010 ";
string filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
string conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager1.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList1.DataSource = DbAccess.GetPageDataSet(AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList1.DataBind();


tablelist = " sell_2009 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager2.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList2.DataSource = DbAccess.GetPageDataSet(AspNetPager2.CurrentPageIndex, this.AspNetPager2.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList2.DataBind();

tablelist = " sell_2008 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager3.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList3.DataSource = DbAccess.GetPageDataSet(AspNetPager3.CurrentPageIndex, this.AspNetPager3.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList3.DataBind();

}
else
{
string tablelist = " sell_2010 ";
string filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
string conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager1.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList1.DataSource = DbAccess.GetPageDataSet(AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList1.DataBind();


tablelist = " sell_2009 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager2.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList2.DataSource = DbAccess.GetPageDataSet(AspNetPager2.CurrentPageIndex, this.AspNetPager2.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList2.DataBind();

tablelist = " sell_2008 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager3.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList3.DataSource = DbAccess.GetPageDataSet(AspNetPager3.CurrentPageIndex, this.AspNetPager3.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList3.DataBind();
}
}


protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
this.AspNetPager1.EnableUrlRewriting = true;
this.AspNetPager1.UrlRewritePattern = "show_sell.aspx?year=2010&page={0}";
this.AspNetPager2.EnableUrlRewriting = true;
this.AspNetPager2.UrlRewritePattern = "show_sell.aspx?year=2009&page={0}";
this.AspNetPager3.EnableUrlRewriting = true;
this.AspNetPager3.UrlRewritePattern = "show_sell.aspx?year=2008&page={0}";
this.bind_default();
}
...全文
167 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
z8129858 2010-11-02
  • 打赏
  • 举报
回复
谢谢 opai72731cl
popai72731cl 2010-11-01
  • 打赏
  • 举报
回复
具体说,在每个栏目外加一个updatepanel,当提交时,
每次只更新一个栏目,而不是整个页面更新。
popai72731cl 2010-11-01
  • 打赏
  • 举报
回复
使用Ajax异步分页,性能会大幅提高。
机器人 2010-11-01
  • 打赏
  • 举报
回复
方法1是减少了2次DB查询。
机器人 2010-11-01
  • 打赏
  • 举报
回复
因为页面不知道是哪个List要重新绑定,所以每次提交每个List都会绑定。
解决办法,是把3个栏目当前的绑定数据存放到ViewState里,再定一个Flag,指定要重新绑定哪一个List。
其他不绑定的List的数据从ViewState里取回。代价就是客户端的页面里存了很多东西!

再或者,你把3个栏目分到3个aspx里,主画面用iframe来显示。这样谁提交刷新谁,相互不影响。
z8129858 2010-11-01
  • 打赏
  • 举报
回复
达人,你在哪里
z8129858 2010-11-01
  • 打赏
  • 举报
回复
1楼朋友,你发的有什么改动么?
z8129858 2010-11-01
  • 打赏
  • 举报
回复
由于绑定的内容数据量挺大,所以现在的方法执行一次很慢,AspNetPager没用过几次,请达人们帮忙看看

自己顶
吴青峰 2010-11-01
  • 打赏
  • 举报
回复
改这个试试:
public void bind_default()
{
if (!string.IsNullOrEmpty(Request.QueryString["year"]))
{
if (Request.QueryString["year"].ToString().Equals("2010"))
{
AspNetPager1.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
AspNetPager2.CurrentPageIndex = 1;
AspNetPager3.CurrentPageIndex = 1;
}
else if (Request.QueryString["year"].ToString().Equals("2009"))
{
AspNetPager1.CurrentPageIndex = 1;
AspNetPager2.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
AspNetPager3.CurrentPageIndex = 1;
}
else if (Request.QueryString["year"].ToString().Equals("2008"))
{
AspNetPager1.CurrentPageIndex = 1;
AspNetPager2.CurrentPageIndex = 1;
AspNetPager3.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
}
string tablelist = " sell_2010 ";
string filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
string conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager1.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList1.DataSource = DbAccess.GetPageDataSet(AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList1.DataBind();


tablelist = " sell_2009 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager2.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList2.DataSource = DbAccess.GetPageDataSet(AspNetPager2.CurrentPageIndex, this.AspNetPager2.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList2.DataBind();

tablelist = " sell_2008 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager3.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList3.DataSource = DbAccess.GetPageDataSet(AspNetPager3.CurrentPageIndex, this.AspNetPager3.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList3.DataBind();

}
else
{
string tablelist = " sell_2010 ";
string filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
string conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager1.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList1.DataSource = DbAccess.GetPageDataSet(AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList1.DataBind();


tablelist = " sell_2009 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager2.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList2.DataSource = DbAccess.GetPageDataSet(AspNetPager2.CurrentPageIndex, this.AspNetPager2.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList2.DataBind();

tablelist = " sell_2008 ";
filed = " id,uid,product,addtime,updatetime,productimage,sm_productimage ";
conditions = " and uid=" + Convert.ToInt32((Str.StringFilter(Session["uid"].ToString()))) + " ";
this.AspNetPager3.RecordCount = DbAccess.ItemsCount("id", tablelist, conditions);
DataList3.DataSource = DbAccess.GetPageDataSet(AspNetPager3.CurrentPageIndex, this.AspNetPager3.PageSize, "id", filed, tablelist, conditions, "order by addtime desc,id desc").Tables[0];
DataList3.DataBind();
}
}


protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
this.AspNetPager1.EnableUrlRewriting = true;
this.AspNetPager1.UrlRewritePattern = "show_sell.aspx?year=2010&page={0}";
this.AspNetPager2.EnableUrlRewriting = true;
this.AspNetPager2.UrlRewritePattern = "show_sell.aspx?year=2009&page={0}";
this.AspNetPager3.EnableUrlRewriting = true;
this.AspNetPager3.UrlRewritePattern = "show_sell.aspx?year=2008&page={0}";
this.bind_default();
}

62,272

社区成员

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

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

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

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