protected void gvKnownProfile_Sorting(object sender, GridViewSortEventArgs e) { DataTable dt = bi.GetMasterKnownProfile(); if (dt != null) { using (DataView dv = new DataView(dt)) { SortDirection sdSortDirection = SortDirection.Ascending; if (Session["SortExpression"] != null) { if (Session["SortExpression"].ToString() == e.SortExpression) { if ((SortDirection)Session["SortDirection"] == SortDirection.Ascending) { sdSortDirection = SortDirection.Descending; } else { sdSortDirection = SortDirection.Ascending; } } else { sdSortDirection = SortDirection.Ascending; } } dv.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(sdSortDirection); Session["SortExpression"] = e.SortExpression; Session["SortDirection"] = sdSortDirection; this.gvKnownProfile.DataSource = dv; this.gvKnownProfile.DataBind(); } } }