protected void GridViewAdminClaims_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(); } GridViewAdminClaims.DataSource = view; GridViewAdminClaims.DataBind(); } }
public void bindGrid() { try { SqlCommand listClaims = new SqlCommand("spAdminListOfClaims", connection); listClaims.CommandType = CommandType.StoredProcedure; connection.Open(); SqlDataAdapter sda = new SqlDataAdapter(listClaims); DataTable dt = new DataTable(); sda.Fill(dt); ViewState["VSTable"] = dt; GridViewAdminClaims.DataSource = dt; GridViewAdminClaims.DataBind(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } }