public void bindGrid() { try { //string txtBeneficiaryID=((Label)Master.FindControl("lblErrMsg")).Text; string txtBeneficiaryID = "20010"; int BeneficiaryID = Convert.ToInt16(txtBeneficiaryID); SqlCommand listClaims = new SqlCommand("spBenefListOfClaims", connection); listClaims.CommandType = CommandType.StoredProcedure; listClaims.Parameters.AddWithValue("@BenefID", BeneficiaryID); connection.Open(); SqlDataAdapter sda = new SqlDataAdapter(listClaims); DataTable dt = new DataTable(); sda.Fill(dt); ViewState["VSTable"] = dt; GridViewBenefClaims.DataSource = dt; GridViewBenefClaims.DataBind(); } catch (Exception e) { throw e; } finally { connection.Close(); } }
protected void GridViewBenefClaims_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(); } GridViewBenefClaims.DataSource = view; GridViewBenefClaims.DataBind(); } }