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优化----大数据下的分页,延迟关联,索引与排序的关系,重复索引与冗余索引,索引碎片与维护
理想的索引,高效的索引建立考虑: :查询频繁度(哪几个字段经常查询就加上索引) :区分度要高 :索引长度要小 : 索引尽量能覆盖常用查询字段(如果把所有的列都加上索引,那么索引就会变得很大) : 索引 ...
随机推荐
- 【MyBatis】MyBatis之别名typeAliases标签的使用
<configuration> <typeAliases> <typeAlias alias="Dept" type="cn.xdl.ent ...
- MongoDB学习笔记(6)--find
MongoDB 查询文档 MongoDB 查询文档使用 find() 方法. find() 方法以非结构化的方式来显示所有文档. 语法 MongoDB 查询数据的语法格式如下: db.collecti ...
- shell脚本监控cpu/内存使用率 转
该脚本检测cpu和内存的使用情况,只需要调整memorySetting.cpuSetting.userEmail要发邮件报警的email地址即可 如果没有配置发邮件参数的哥们,已配置了的,直接飞到代码 ...
- Oracle 12C -- truncate的级联操作
在之前的版本中,存在外键约束时,无法直接truncate父表.在12C中,对truncate操作添加了级联操作特性. 前提是创建外键约束时,使用了"on delete casacde&quo ...
- Linux VFS数据结构
先说明一下,linux内核中各种数据结构也不停的在变,所以不同版本的内核各个数据结构的定义可能会差别很大,这一组关于linux 文件系统的文章中的代码都摘自linux-2.6.34.1. VFS依赖于 ...
- Android KLog源代码分析
Android KLog源代码分析 Android KLog源代码分析 代码结构 详细分析 BaseLog FileLog JsonLog XmlLog 核心文件KLogjava分析 遇到的问题 一直 ...
- 利用 PowerShell 分析SharePoint WebApplication 体系结构
之前一篇文章<两张图看清SharePoint 2013 Farm 逻辑体系结构>谈到Web Application,Content Database,Site Collection的关系. ...
- ekho安装及测试(中文文字转语音)
1. 官网下载源码包 地址:http://www.eguidedog.net/ekho.php 2. 安装 xz -d ekho-7.5.tar.xz tar -xvf ekho-7.5.tar ap ...
- [转]使用自定义HttpMessageConverter对返回内容进行加密
今天上午技术群里的一个人问” 如何在 Spring MVC 中统一对返回的 Json 进行加密?”. 大部分人的第一反应是通过 Spring 拦截器(Interceptor)中的postHandler ...
- 一个将java事物的非常好的栗子
地址:http://www.cnblogs.com/davenkin/archive/2013/02/16/java-tranaction-1.html