国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET 翻頁后繼續(xù)維持排序

2024-07-10 13:05:58
字體:
供稿:網(wǎng)友


 要想實現(xiàn)翻頁后繼續(xù)排序,實現(xiàn)這樣的效果:

  比如共 15筆記錄,每頁顯示10條

  則排序時:第一頁將前10條記錄排序,翻第二頁時后五條再單獨排序.

  要注意以下幾點:

  1.如果數(shù)據(jù)很多,最好不要把數(shù)據(jù)集放到緩存中(viewstate),影響性能

  2. viewstate中存放上次是哪個e.expression并且存放此e.expression是升序還是降序

  示例如下:

  1.現(xiàn)有的排序事件是這樣寫的,這個是點擊上面排序標(biāo)題時用:

private void grdprojtrace_sortcommand(object source, datagridsortcommandeventargs e)
{
 this.grdprojtrace.currentpageindex = 0;
 dataview dv = 得到數(shù)據(jù)代碼;
 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(e.sortexpression == "customername")
 {
  if(strsort != "customername")
  {
   this.viewstate["sortexpresstion"] = ustomername0";
   dv.sort = "customername desc";
  }
  else
  {
   if(strorder == "0")
   {
    this.viewstate["sortexpresstion"] = "customername1";
    dv.sort = "customername asc";
   }
   else
   {
    this.viewstate["sortexpresstion"] = "customername0";
    dv.sort = "customername desc";
   }
  }
 }
 if(e.sortexpression == "fullname")
 {
  if(strsort != "fullname")
  {
   this.viewstate["sortexpresstion"] = "fullname0";
   dv.sort = "fullname desc";
  }
  else
  {
   if(strorder == "0")
   {
    this.viewstate["sortexpresstion"] = "fullname1";
    dv.sort = "fullname asc";
   }
   else
   {
    this.viewstate["sortexpresstion"] = "fullname0";
    dv.sort = "fullname desc";
   }
  }
 }
 this.grdprojtrace.datasource = dv;
 this.grdprojtrace.databind();
}

  2.下面這個方法是自己寫的,翻頁事件中調(diào)用。

private void changepagedatabind()
{
 dataview dv = 得到數(shù)據(jù)代碼;
 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();
}

  上面兩方法只要修改要排序的字段名,就可以直接調(diào)用了.

  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)
 {
  //異常
 }
}


 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 淳安县| 潮安县| 襄樊市| 昭觉县| 大宁县| 天气| 佛冈县| 新干县| 宜宾市| 抚松县| 郴州市| 尉犁县| 房山区| 满城县| 陆川县| 新昌县| 丁青县| 宁都县| 泸西县| 海淀区| 遵化市| 昭苏县| 镇巴县| 定南县| 南木林县| 长乐市| 随州市| 绥滨县| 裕民县| 阜宁县| 镇平县| 岫岩| 抚顺市| 寿光市| 买车| 张家界市| 华蓥市| 盘锦市| 容城县| 芷江| 凉山|