如果是在前台写数据源的话,例如:
SelectMethod="GetMethodAll">
就可以这样写:
protected void sgvw_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable sortDataTable = sgvw.DataSource as DataTable;
if (sortDataTable != null)
{
DataView sortDataView = new DataView(sortDataTable);
sortDataView.Sort = e.SortExpression + "" + ConvertSortDirection(e.SortDirection);
sgvw.DataSource=sortDataView;
sgvw.DataBind();
}
}
//改变排序方向
private string ConvertSortDirection(SortDirection Direction)
{
string a_SortDirection = string.Empty;
switch (Direction)
{
case SortDirection.Ascending:
a_SortDirection = "ASC";
break;
case SortDirection.Descending:
a_SortDirection = "DESC";
break;
}
return a_SortDirection;
}
但是如果在后台绑定数据源的话,这个事件就不能触发,怎么办呢?可以用另一个事件:
protected void sgvw_NoSourceControlSorting(object sender, Suzsoft.Web.UI.EventArg.SGridViewSortEventArgs e)
{
DataSet ds = new DataSet();
DataSet dsNew = new DataSet();
ds = (DataSet)ViewState["ds"];
if (ds != null)
{
dsNew = PermissionControl.DataSetFilter(base.Login_UserID, " ", ds);//信息过滤
}
if (dsNew != null && dsNew.Tables.Count > 0)
{
e.DataSource = dsNew.Tables[0];
}
}