protected void GridViewAdminPolicies_Sorting(object sender, GridViewSortEventArgs e) { DataTable datatable = (DataTable)ViewState["table"]; if (datatable != null) { DataView view = new DataView(datatable); if (Convert.ToString(ViewState["sort"]).Contains("ASC") || Convert.ToString(ViewState["sort"]) == "") { view.Sort = e.SortExpression + " " + "DESC"; ViewState["sort"] = view.Sort.ToString(); } else { view.Sort = e.SortExpression + " " + "ASC"; ViewState["sort"] = view.Sort.ToString(); } GridViewAdminPolicies.DataSource = view; GridViewAdminPolicies.DataBind(); } }
public void bindGrid() { try { SqlCommand listPolicies = new SqlCommand("spAdminListOfPolicies", connection); listPolicies.CommandType = CommandType.StoredProcedure; connection.Open(); SqlDataAdapter sda = new SqlDataAdapter(listPolicies); DataTable dt = new DataTable(); sda.Fill(dt); ViewState["VSTable"] = dt; GridViewAdminPolicies.DataSource = dt; GridViewAdminPolicies.DataBind(); } catch (Exception e) { throw e; } finally { connection.Close(); } }