DataGride排序小结

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";
}
}
原文地址:https://www.cnblogs.com/happygx/p/2022465.html