protected void GridViewListHospitals_Sorting(object sender, GridViewSortEventArgs e) { try { 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(); } GridViewListHospitals.DataSource = view; GridViewListHospitals.DataBind(); } } catch (Exception ex) { throw ex; } finally { } }
//public void bindGrid() //{ // ListOfHospitals(); //} //public DataTable ListOfHospitals() //{ // try // { // SqlCommand listHospitals = new SqlCommand("spListOfHospitals", connection); // listHospitals.CommandType=CommandType.StoredProcedure; // connection.Open(); // SqlDataAdapter da=new SqlDataAdapter(listHospitals); // DataTable dt=new DataTable(); // return dt; // } // catch (Exception e) // { // throw e; // } // finally // { // connection.Close(); // } //} public void grid() { SqlCommand listHospitals = new SqlCommand("spListOfHospitals", connection); listHospitals.CommandType = CommandType.StoredProcedure; SqlDataAdapter adap = new SqlDataAdapter(listHospitals); DataTable dt = new DataTable(); adap.Fill(dt); ViewState["table"] = dt; GridViewListHospitals.DataSource = dt; GridViewListHospitals.DataBind(); }