一个页面有3个栏目,没个栏目都有一个AspNetPager,逐步调试,每点一次分页,后台都执行3次绑定,求达人帮忙优化一下。
下面是绑定方法和事件
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();
}