protected void grdOrders_Sorting(object sender, GridViewSortEventArgs e) >{ > // Get the sort direction from the event args > string SortOrder = e.SortDirection == SortDirection.Ascending ? "ASC" : "DESC"; > > // Get the SortExpression from the event args and use it along with the sort order to > // set the DefaultView's Sort property > DataTable dtOrders = (DataTable)Session["dtOrders"]; > dtOrders.DefaultView.Sort = e.SortExpression + " " + SortOrder; > > // Save the DataTable back to the session, then rebind the GridView > Session["dtOrders"] = dtOrders; > this.grdOrders.DataSource = dtOrders.DefaultView; > this.grdOrders.DataBind(); >}>
Protected Sub grdOrders_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdOrders.Sorting > > '' Get the sort direction from the event args > Dim SortOrder As String = IIf(e.SortDirection = SortDirection.Ascending, "ASC", "DESC") > > '' Get the SortExpression from the event args and use it along with the sort order to > '' set the DefaultView's Sort property > Dim dtOrders As DataTable = CType(Session("dtOrders"), DataTable) > dtOrders.DefaultView.Sort = e.SortExpression + " " + SortOrder > > '' Save the DataTable back to the session, then rebind the GridView > Session("dtOrders") = dtOrders > Me.grdOrders.DataSource = dtOrders.DefaultView > Me.grdOrders.DataBind() > >End Sub