Gridview排序与分页-不使用“DataSourceControl DataSource”的情况下如何分页和排序 ...
如果你在GridView控件上设置 AllowPaging="true" or AllowSorting="true" 而没有使用使用数据源控件 DataSource (i.e. SqlDataSource, ObjectDataSource),运行则会出现下列错误:
当你在GridView控件上单击下一页时:
The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled.
当你点击排序时,则回出现:
The GridView 'GridViewID' fired event Sorting which wasn't handled.
不使用“DataSourceControl DataSource”的情况下如何分页和排序 ...
你必须添加一个操作才可以排序及分页。。
public class WebHandler
{
private WebHandler() { }
public static readonly WebHandler Instance = new WebHandler(); #region GridView Handler public string GridViewSortExpression
{
get { return HttpContext.Current.Session["SortExpression"] as string ?? string.Empty; }
set { HttpContext.Current.Session["SortExpression"] = value; }
} public string GridViewSortDirection
{
get { return HttpContext.Current.Session["SortDirection"] as string ?? "ASC"; }
set { HttpContext.Current.Session["SortDirection"] = value; }
} public string GetSortDirection()
{
switch (GridViewSortDirection)
{
case "ASC":
GridViewSortDirection = "DESC";
break;
case "DESC":
GridViewSortDirection = "ASC";
break;
}
return GridViewSortDirection;
} public DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
{
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
if (GridViewSortExpression != string.Empty)
{
if (isPageIndexChanging)
{
dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
}
else
{
dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
}
}
return dataView;
}
else
{
return new DataView();
}
} #endregion
}
aspx & aspx.cs
<asp:GridView ID="gvInvoiceHistory" runat="server" AllowPaging="True" OnPageIndexChanging="gvInvoiceHistory_PageIndexChanging" OnRowCreated="gvInvoices_RowCreated" OnSorting="gvInvoiceHistory_Sorting" AllowSorting="True" AutoGenerateColumns="False" > //aspx.cs
private readonly WebHandler webHandler = WebHandler.Instance; protected void gvInvoiceHistory_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvInvoiceHistory.DataSource = webHandler.SortDataTable(GetInvoiceList(), true);
gvInvoiceHistory.PageIndex = e.NewPageIndex;
gvInvoiceHistory.DataBind();
} protected void gvInvoiceHistory_Sorting(object sender, GridViewSortEventArgs e)
{
webHandler.GridViewSortExpression = e.SortExpression;
int pageIndex = gvInvoiceHistory.PageIndex;
gvInvoiceHistory.DataSource = webHandler.SortDataTable(GetInvoiceList(), false);
gvInvoiceHistory.DataBind();
gvInvoiceHistory.PageIndex = pageIndex;
} public virtual DataTable GetInvoiceList()
{
DataTable result = new DataTable();
...........
return result;
}
//DataBind 排序图标丢失,
protected virtual void gvInvoices_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
if (cell.HasControls())
{
LinkButton button = cell.Controls[] as LinkButton;
if (button != null)
{
//Label lblsort = new Label();
if (ddlParentInvoice.SelectedValue != "-1" && webHandler.GridViewSortExpression == button.CommandArgument)
{
Image image = new Image();
if (webHandler.GetSortDirection() == "ASC")
{
image.SkinID = "SortArrowDown";
//lblsort.Text = " <font>▼</font>";
}
else
{
image.SkinID = "SortArrowUp";
//lblsort.Text = " <font>▲</font>";
}
cell.Controls.Add(image);
}
}
}
}
}
}
Gridview排序与分页-不使用“DataSourceControl DataSource”的情况下如何分页和排序 ...的更多相关文章
- MYSQL的大数据量情况下的分页查询优化
最近做的项目需要实现一个分页查询功能,自己先看了别人写的方法: <!-- 查询 --> <select id="queryMonitorFolder" param ...
- 飘逸的python - 有的升序有的降序的情况下怎么多条件排序
之前在统计导出各区服玩家消费的时候需要进行升序降序混搭的多条件排序. 需求是这样的.区服从小到大排,如果区服相同,则按消费从大到小排. 实现方法是利用python的sort算法是稳定排序,对数据进行多 ...
- MySQL分页优化中的“INNER JOIN方式优化分页算法”到底在什么情况下会生效?
本文出处:http://www.cnblogs.com/wy123/p/7003157.html 最近无意间看到一个MySQL分页优化的测试案例,并没有非常具体地说明测试场景的情况下,给出了一种经典的 ...
- EasyUI Datagrid 分页的情况下实现点击表头的小三角图标对数据库中所有数据重新排序
说明一下: 当点击 datagrid 表头某一列的小三角图标时,easyui 本身是有排序的,但是在当我们对 datagrid 进行了分页的情况下,点击排序只是对当前页的数据进行排序,而需求需要我对数 ...
- 小书MybatisPlus第4篇-表格分页与下拉分页查询
本文为mybatis系列文档的第4篇,前三篇请访问下面的网址. 小书MybatisPlus第1篇-整合SpringBoot快速开始增删改查 小书MybatisPlus第2篇-条件构造器的应用及总结 小 ...
- “ShardingCore”是如何针对分表下的分页进行优化的
分表情况下的分页如何优化 首先还是要给自己的开原框架打个广告 sharding-core 针对efcore 2+版本的分表组件,首先我们来快速回顾下目前市面上分表下针对分页常见的集中解决方案 分表解决 ...
- GridView自定义分页样式(上一页,下一页,到第几页)
今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1). 图(1)GridView分页效果 自定义G ...
- 分页技巧_改进JSP页面中的公共分页代码_实现分页时可以有自定义的过滤与排序条件
分页技巧__改进JSP页面中的公共分页代码 自定义过滤条件问题 只有一个url地址不一样写了很多行代码 public>>pageView.jspf添加 分页技巧__实现分页时可以有自定义的 ...
- mysql优化----大数据下的分页,延迟关联,索引与排序的关系,重复索引与冗余索引,索引碎片与维护
理想的索引,高效的索引建立考虑: :查询频繁度(哪几个字段经常查询就加上索引) :区分度要高 :索引长度要小 : 索引尽量能覆盖常用查询字段(如果把所有的列都加上索引,那么索引就会变得很大) : 索引 ...
随机推荐
- idea 不下载jar包
是因为用的gradle 然后没有设置gradle jvm
- Centos 安装GIT 1.7.1
在Linux上安装Git 1.首先,你可以试着输入git,看看系统有没有安装Git: git 2.安装GIT https://git-scm.com/download/linux yum instal ...
- 关于tensorboard启动问题
我在学习过程中遇到了tensorboard无法启动的问题. 按照网上的教程,我无法正常启动tensorboard,全过程没有报错,但是打开tensorboard显示 No dashboards are ...
- Oracle 12C -- clone a non-cdb as a pdb
将non-CDB置为只读模式: $ sqlplus '/as sysdba' SQL> select name, decode(cdb, 'YES', 'Multitenant Option e ...
- netty服务端实现心跳超时的主动拆链
一.服务器启动示例: public class MySocketServer { protected static Logger logger = LoggerFactory.getLogger(My ...
- android发送短信代码(短信内容超长处理)
一条短信只可容纳70个中文,所以当短信长度超过70个中文字符时程序就要特殊处理了. 有两种方式: 1.通过sendTextMessage()方法依次发送拆分后的短信,该方式有个弊端就是用户会分条收到短 ...
- 使用vs的查找功能,简单大概的统计vs中的代码行数
VS强大的查找功能,可以使用正则表达式来进行查找,这里统计代码行数的原理就是: 在所有指定文件中进行搜索,统计匹配的文本行数. 但是匹配的行需要满足:非注释.非空等特殊非代码行. 使用Ctrl+Shi ...
- Android build.gradle
apply plugin: 'com.android.application' android { /*编译版本 , 因此我们强烈推荐总是使用最新的 SDK 进行编译 targetSdkVersion ...
- [na]二层sw数据交换
1,同vlan下,两台pc配置了GW,arp请求过程. Pc1 ping pc0的时候,触发pc1的arp请求,发给GW后,GW继续发给pc0(同一个vlan),pc0收到后给pc1回复.Pc1发出i ...
- nodejs文件上传报错总结
语法: fs.rename(oldPath,newPath,callback) 今天在使用formidable模块做图片上传处理的时候,fs.rename方法的报了一个这样的错:cross-devic ...