如果你在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”的情况下如何分页和排序 ...的更多相关文章

  1. MYSQL的大数据量情况下的分页查询优化

    最近做的项目需要实现一个分页查询功能,自己先看了别人写的方法: <!-- 查询 --> <select id="queryMonitorFolder" param ...

  2. 飘逸的python - 有的升序有的降序的情况下怎么多条件排序

    之前在统计导出各区服玩家消费的时候需要进行升序降序混搭的多条件排序. 需求是这样的.区服从小到大排,如果区服相同,则按消费从大到小排. 实现方法是利用python的sort算法是稳定排序,对数据进行多 ...

  3. MySQL分页优化中的“INNER JOIN方式优化分页算法”到底在什么情况下会生效?

    本文出处:http://www.cnblogs.com/wy123/p/7003157.html 最近无意间看到一个MySQL分页优化的测试案例,并没有非常具体地说明测试场景的情况下,给出了一种经典的 ...

  4. EasyUI Datagrid 分页的情况下实现点击表头的小三角图标对数据库中所有数据重新排序

    说明一下: 当点击 datagrid 表头某一列的小三角图标时,easyui 本身是有排序的,但是在当我们对 datagrid 进行了分页的情况下,点击排序只是对当前页的数据进行排序,而需求需要我对数 ...

  5. 小书MybatisPlus第4篇-表格分页与下拉分页查询

    本文为mybatis系列文档的第4篇,前三篇请访问下面的网址. 小书MybatisPlus第1篇-整合SpringBoot快速开始增删改查 小书MybatisPlus第2篇-条件构造器的应用及总结 小 ...

  6. “ShardingCore”是如何针对分表下的分页进行优化的

    分表情况下的分页如何优化 首先还是要给自己的开原框架打个广告 sharding-core 针对efcore 2+版本的分表组件,首先我们来快速回顾下目前市面上分表下针对分页常见的集中解决方案 分表解决 ...

  7. GridView自定义分页样式(上一页,下一页,到第几页)

    今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1). 图(1)GridView分页效果 自定义G ...

  8. 分页技巧_改进JSP页面中的公共分页代码_实现分页时可以有自定义的过滤与排序条件

    分页技巧__改进JSP页面中的公共分页代码 自定义过滤条件问题 只有一个url地址不一样写了很多行代码 public>>pageView.jspf添加 分页技巧__实现分页时可以有自定义的 ...

  9. mysql优化----大数据下的分页,延迟关联,索引与排序的关系,重复索引与冗余索引,索引碎片与维护

    理想的索引,高效的索引建立考虑: :查询频繁度(哪几个字段经常查询就加上索引) :区分度要高 :索引长度要小 : 索引尽量能覆盖常用查询字段(如果把所有的列都加上索引,那么索引就会变得很大) : 索引 ...

随机推荐

  1. ubuntu(14.04) 下安装yaf拓展

    #wget http://pecl.PHP.net/get/yaf-2.2.9.tgz #tar zxvf yaf-.tgz #cd yaf- [root@bogon yaf-]# whereis p ...

  2. 【ASP.NET】@RenderBody,@RenderPage,@RenderSection的使用

    @RenderBody @RenderBody是布局页(_Layout.cshtml)通过占位符@RenderBody占用独立部分,当创建基于此布局页的试图时,视图的内容会和布局页合并,而新创建的视图 ...

  3. 【Oracle】Oracle索引

    在关系数据库中,索引是一种与表有关的数据库结构,它可以使对应于表的SQL语句执行得更快.索引的作用相当于图书的目录,可以根据目录中的页码快速找到所需的内容. 对于数据库来说,索引是一个必选项,但对于现 ...

  4. log4j(五)——如何控制不同目的地的日志输出?

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 二:老规矩,先来个栗子,然后再聊聊感受 import org.apache.log4j.*; import java.io ...

  5. Spark日志清洗

    日志数据清洗,主要采用spark 的定时任务,清洗出有效数据,并保存到hive数据仓库中存储.常用流程如下: 参考:https://gaojianhua.gitbooks.io/bigdata-wik ...

  6. YY老总李学凌给记者们的几句话

    从记者到总编,从狗狗.多玩到如今的 YY.100 教育,似乎李学凌在这么多年来一直没有放缓过脚步.作为记者转型的成功案例,李学凌总结记者生涯有几方面令其获益匪浅: 1.平常心.对待再高层次的人,也用一 ...

  7. Android的 EditText的inputType类型

    android开发过程中突然发现的warning EditText 报出 “This text field does not specify an inputType or a hint”   原因: ...

  8. ORA-65179: cannot keep datafiles for a pluggable database that is not unplugged

    SQL> drop pluggable database pdb2; drop pluggable database pdb2 * ERROR at line : ORA-: cannot ke ...

  9. Photoshop做32位带Alpha通道的bmp图片

    原文链接: http://blog.sina.com.cn/s/blog_65c0cae801016e5u.html   批量制作32位带Alpha通道的bmp图片,可以制作一个动作,内容可以如下: ...

  10. asp.net中WinForm使用单例模式示例

    例如在Windows应用程序中用下面代码打开一个窗体: 代码如下 复制代码 private void button1_Click(object sender, EventArgs e){ (new A ...