Private Sub DG_ContentList_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DG_ContentList.SortCommand
'排序
If Me.ViewState.Item("SortType") Is Nothing Then
Me.DataView.Sort = e.SortExpression
Me.ViewState.Item("SortType") = " desc"
Else
Me.DataView.Sort = e.SortExpression.ToString & Me.ViewState.Item("SortType")
If Me.ViewState.Item("SortType") = "" Then
Me.ViewState.Item("SortType") = " desc"
Else
Me.ViewState.Item("SortType") = ""
End If
End If
Me.DG_ContentList.DataBind()
你只要点击那个字段的标题就可以以那个列排序,
如果你想用代码控制,那么使用DataView里的Sort
private void SortByTwoColumns()
{
// Get the DefaultViewManager of a DataTable.
DataView myDataView = DataTable1.DefaultView;
// By default, the first column sorted ascending.
myDataView.Sort = "State, ZipCode DESC";
}