DataGride排序小结
时间:2011-04-20 来源:happygx
DataGride排序
首先拖入DataGride控件
现在前台拖入隐含控件<INPUT id="sortfield" type="hidden" value="UserID desc" name="sortfield" runat="server">
设定排序字段
然后再启用SortCommand事件

//排序
private void Dg_Directory_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
CommMethod.DataGridSort(e.SortExpression, sortfield);
this.sortval.Value = e.SortExpression;
GetData(Page1.NowPage); //绑定数据
}
调用排序方法

/// <summary>
/// 对DataGrid进行排序
/// </summary>
/// <param name="p_Exp">排序表达式</param>
/// <param name="p_SortField"></param>
public static void 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";
}
}
相关阅读 更多 +