ASP.NET 翻页后继续维持排序
2006-08-14 16:36
483 查看
asp.net 翻页后继续维持排序
要想实现翻页后继续排序,实现这样的效果: 比如共 15笔记录,每页显示10条
则排序时:第一页将前10条记录排序,翻第二页时后五条再单独排序.
要注意以下几点:
1.如果数据很多,最好不要把数据集放到缓存中(viewstate),影响性能
2. viewstate中存放上次是哪个e.expression并且存放此e.expressi
示例如下:
1.现有的排序事件是这样写的,这个是点击上面排序标题时用:
private void grdprojtrace_sortcommand(object source, datagridsortcommandeventargs e)
{
this.grdprojtrace.currentpageindex = 0;
dataview dv = 得到数据代码;
string strsort = "";
string strorder ="";//排序方式。0,降序,1升序
if(viewstate["sortexpressti != 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["sortexpressti = ustomername0";
dv.sort = "customername desc";
}
else
{
if(strorder == "0")
{
this.viewstate["sortexpressti = "customername1";
dv.sort = "customername asc";
}
else
{
this.viewstate["sortexpressti = "customername0";
dv.sort = "customername desc";
}
}
}
if(e.sortexpression == "fullname")
{
if(strsort != "fullname")
{
this.viewstate["sortexpressti = "fullname0";
dv.sort = "fullname desc";
}
else
{
if(strorder == "0")
{
this.viewstate["sortexpressti = "fullname1";
dv.sort = "fullname asc";
}
else
{
this.viewstate["sortexpressti = "fullname0";
dv.sort = "fullname desc";
}
}
}
this.grdprojtrace.datasource = dv;
this.grdprojtrace.databind();
}
2.下面这个方法是自己写的,翻页事件中调用。
private void changepagedatabind()
{
dataview dv = 得到数据代码;
string strsort = "";
string strorder ="";//排序方式。0,降序,1升序
if(viewstate["sortexpressti != 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["sortexpressti != null)
{
if(strsort == "customername")
{
if(strorder == "1")
{
this.viewstate["sortexpressti = "customername1";
dv.sort = "customername asc";
}
else
{
this.viewstate["sortexpressti = "customername0";
dv.sort = "customername desc";
}
}
}
if(this.viewstate["sortexpressti != null)
{
if(strsort == "fullname")
{
if(strorder == "1")
{
this.viewstate["sortexpressti = "fullname1";
dv.sort = "fullname asc";
}
else
{
this.viewstate["sortexpressti = "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)
{
//异常
}
}
要想实现翻页后继续排序,实现这样的效果: 比如共 15笔记录,每页显示10条
则排序时:第一页将前10条记录排序,翻第二页时后五条再单独排序.
要注意以下几点:
1.如果数据很多,最好不要把数据集放到缓存中(viewstate),影响性能
2. viewstate中存放上次是哪个e.expression并且存放此e.expressi
示例如下:
1.现有的排序事件是这样写的,这个是点击上面排序标题时用:
private void grdprojtrace_sortcommand(object source, datagridsortcommandeventargs e)
{
this.grdprojtrace.currentpageindex = 0;
dataview dv = 得到数据代码;
string strsort = "";
string strorder ="";//排序方式。0,降序,1升序
if(viewstate["sortexpressti != 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["sortexpressti = ustomername0";
dv.sort = "customername desc";
}
else
{
if(strorder == "0")
{
this.viewstate["sortexpressti = "customername1";
dv.sort = "customername asc";
}
else
{
this.viewstate["sortexpressti = "customername0";
dv.sort = "customername desc";
}
}
}
if(e.sortexpression == "fullname")
{
if(strsort != "fullname")
{
this.viewstate["sortexpressti = "fullname0";
dv.sort = "fullname desc";
}
else
{
if(strorder == "0")
{
this.viewstate["sortexpressti = "fullname1";
dv.sort = "fullname asc";
}
else
{
this.viewstate["sortexpressti = "fullname0";
dv.sort = "fullname desc";
}
}
}
this.grdprojtrace.datasource = dv;
this.grdprojtrace.databind();
}
2.下面这个方法是自己写的,翻页事件中调用。
private void changepagedatabind()
{
dataview dv = 得到数据代码;
string strsort = "";
string strorder ="";//排序方式。0,降序,1升序
if(viewstate["sortexpressti != 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["sortexpressti != null)
{
if(strsort == "customername")
{
if(strorder == "1")
{
this.viewstate["sortexpressti = "customername1";
dv.sort = "customername asc";
}
else
{
this.viewstate["sortexpressti = "customername0";
dv.sort = "customername desc";
}
}
}
if(this.viewstate["sortexpressti != null)
{
if(strsort == "fullname")
{
if(strorder == "1")
{
this.viewstate["sortexpressti = "fullname1";
dv.sort = "fullname asc";
}
else
{
this.viewstate["sortexpressti = "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)
{
//异常
}
}
相关文章推荐
- ASP.NET 翻页后继续维持排序
- ASP.NET翻页后继续维持排序
- ASP.Net 翻页后继续维持排序
- ASP.Net 翻页后继续维持排序(转)
- ASP.NET翻页后继续维持排序
- ASP.NET 翻页后继续维持排序
- ASP.Net 翻页后继续维持排序
- ASP.Net中DataGrid翻页后继续保持(当前排序)显示
- ASP.Net中DataGrid翻页后继续保持(当前排序)显示
- ASP.Net中DataGrid翻页后继续保持(当前排序)显示
- ASP.Net中DataGrid翻页后继续保持(当前排序)显示
- ASP.Net中DataGrid翻页后继续保持(当前排序)显示
- ASP.NET - 维持 ViewState
- 【asp.net 】使用js结合hidden控件实现在后台运行一段程序后提示确认,确认通过后继续执行后台代码~~~
- asp.net内置对象----再一次被周公夜话吸引(继续收藏)
- [asp.net+Sql]关于树的排序
- 【EntityFramework系列教程三,翻译】在ASP.NET MVC程序中使用EntityFramework对数据进行排序、过滤筛选以及实现分页
- ASP.NET 2.0数据处理之高级分页/排序
- 让Asp.NET的DataGrid可排序、可选择、可分页
- 在ASP.NET 2.0中操作数据之二十七:创建自定义排序用户界面