当前位置:首页 > 网络编程 > WEB编程 > ASP.net > ASP.NET翻页后继续维持排序(2)

ASP.NET翻页后继续维持排序(2)

点击次数:22 次 发布日期:2008-11-27 02:19:07 作者:源代码网
源代码网推荐   2.下面这个方法是自己写的,翻页事件中调用。
  
  private void ChangePageDataBind()
  {
   DataView dv = 得到数据代码;
   string strSort = "";
   string strOrder ="";//排序方式。0,降序,1升序
   if(ViewState["SortExpresstion"] != null)
   {
    strSort = ViewState["SortExpresstion"].ToString();
    strSort = strSort.Substring(0,strSort.Length -1);
    strOrder = ViewState["SortExpresstion"].ToString();
    strOrder = strOrder.Substring(strOrder.Length -1);
   }
   if(this.ViewState["SortExpresstion"] != null)
   {
    if(strSort == "CustomerName")
    {
     if(strOrder == "1")
     {
      this.ViewState["SortExpresstion"] = "CustomerName1";
      dv.Sort = "CustomerName ASC";
     }
     else
     {
      this.ViewState["SortExpresstion"] = "CustomerName0";
      dv.Sort = "CustomerName DESC";
     }
    }
   }
   if(this.ViewState["SortExpresstion"] != null)
   {
    if(strSort == "fullName")
    {
     if(strOrder == "1")
     {
      this.ViewState["SortExpresstion"] = "fullName1";
      dv.Sort = "fullName ASC";
     }
     else
     {
      this.ViewState["SortExpresstion"] = "fullName0";
      dv.Sort = "fullName DESC";
     }
    }
   }
   this.grdProjTrace.DataSource = dv;
   this.grdProjTrace.DataBind();
  }
  
    上面两方法只要修改要排序的字段名,就可以直接调用了.
  
    1、方法很简单实用,这里就不说了。
  
    2、方法是这样用的:
  
  private void grdProjTrace_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  {
   try
   {
    try
    {
     this.grdProjTrace.CurrentPageIndex = e.NewPageIndex;
    }
    catch
    {
     this.grdProjTrace.CurrentPageIndex = 0;
    }
  
    this.ChangePageDataBind();
   }
   catch(System.Exception errWS)
   {
    //异常
   }
  }


源代码网推荐
源代码网推荐
源代码网推荐
源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华