在asp.net中排序gridview的列c#
发布时间:2020-05-23 22:07:41 所属栏目:asp.Net 来源:互联网
导读:任何人都可以告诉函数在c#asp.net中对gridview的列进行排序. gridview的数据绑定来自使用linq创建的datacontext.我想单击列的标题来对数据进行排序. 谢谢! 要做到这一点,您需要做两件事. 保持排序状态为viewstate(SortDirection和SortExpression) 您可以根据
|
任何人都可以告诉函数在c#asp.net中对gridview的列进行排序. gridview的数据绑定来自使用linq创建的datacontext.我想单击列的标题来对数据进行排序. 谢谢! 解决方法要做到这一点,您需要做两件事.>保持排序状态为viewstate(SortDirection和SortExpression) 手动处理网格中的Sorting事件并使用我编写的这个帮助器按SortExpression和SortDirection排序: public static IQueryable<T> SortBy<T>(IQueryable<T> source,string sortExpression,SortDirection direction) {
if (source == null) {
throw new ArgumentNullException("source");
}
string methodName = "OrderBy";
if (direction == SortDirection.Descending) {
methodName += "Descending";
}
var paramExp = Expression.Parameter(typeof(T),String.Empty);
var propExp = Expression.PropertyOrField(paramExp,sortExpression);
// p => p.sortExpression
var sortLambda = Expression.Lambda(propExp,paramExp);
var methodCallExp = Expression.Call(
typeof(Queryable),methodName,new[] { typeof(T),propExp.Type },source.Expression,Expression.Quote(sortLambda)
);
return (IQueryable<T>)source.Provider.CreateQuery(methodCallExp);
}
db.Products.SortBy(e.SortExpression,e.SortDirection) 查看my blog post 如何执行此操作: (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 使用MVC将数据导入局部视图或布局
- asp.net-mvc-4 – 在VS2012中运行代码分析时出错
- asp.net-core – 如何在Entity Framework Core中运行存储过
- ASP.NET Web API 2:通过本机移动(iOS)应用程序与外部提供程
- asp.net-membership – 将ASP.NET成员资格提供程序与现有用
- ASP.NET对txt文件相关操作(读
- asp.net-mvc-3 – 如何指定默认LayoutPage在Razor在ASP.NET
- asp.net – 为什么GridView在回发后不会将标题行呈现为标题
- asp.net-mvc – 无法加载文件或程序集”或其依赖项之一.该进
- asp.net – 如何创建一个HTML Helper来扩展TextBoxFor()以添
推荐文章
站长推荐
- asp.net-mvc-2 – 什么是Html.Validate和Html.Va
- asp.net-mvc-3 – AutoMapper线程问题(缺少类型映
- asp.net-mvc – 使用signalr时,将有任何连接限制
- 在ASP.net中模拟HttpSessionState进行单元测试
- ASP.net MVC ValidationSummary总是被渲染
- asp.net – 单独配置文件为web.config的部分
- asp.net-mvc-5 – 在MVC 5期货中找不到Html.Seri
- asp.net-mvc – IIS 7上的ASP.net MVC返回空白页
- asp.net-mvc – MVC4 Razor对大括号感到困惑
- 依赖于文件的.net核心asp.net单元测试 – appset
热点阅读
