posts - 162,comments - 41,views - 30万

DataGride排序

首先拖入DataGride控件

现在前台拖入隐含控件<INPUT id="sortfield" type="hidden" value="UserID desc" name="sortfield" runat="server">

设定排序字段

然后再启用SortCommand事件

复制代码
View Code
//排序
privatevoid Dg_Directory_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
CommMethod.DataGridSort(e.SortExpression, sortfield);
this.sortval.Value = e.SortExpression;
GetData(Page1.NowPage);
//绑定数据
}
复制代码

调用排序方法

复制代码
View Code
///<summary>
/// 对DataGrid进行排序
///</summary>
///<param name="p_Exp">排序表达式</param>
///<param name="p_SortField"></param>
publicstaticvoid DataGridSort(string p_SortExp, HtmlInputHidden p_SortField)
{
if (p_SortField.Value.EndsWith("desc") ==false)
{
p_SortField.Value
= p_SortExp +" desc";
}
else
{
p_SortField.Value
= p_SortExp +" asc";
}
}
复制代码
posted on   高兴happy  阅读(322)  评论(0编辑  收藏  举报
编辑推荐:
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
阅读排行:
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率
· AI Agent爆火后,MCP协议为什么如此重要!
< 2011年4月 >
27 28 29 30 31 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
1 2 3 4 5 6 7

点击右上角即可分享
微信分享提示