protected void gvManageList_Sorting(object sender, GridViewSortEventArgs e) { try { gvManageList.EditIndex = -1; string sortExpression = e.SortExpression; if (GridViewSortDirection == SortDirection.Ascending) { GridViewSortDirection = SortDirection.Descending; BindManageListGrid(sortExpression, " DESC "); } else { GridViewSortDirection = SortDirection.Ascending; BindManageListGrid(sortExpression, " ASC "); } } catch (Exception ex) { ex.HandleException(ExceptionLayer.UI); Response.Redirect("CustomError.aspx", false); } } private SortDirection GridViewSortDirection { get { if (ViewState["sortDirection"] == null) ViewState["sortDirection"] = SortDirection.Ascending; return (SortDirection)ViewState["sortDirection"]; } set { ViewState["sortDirection"] = value; } } public void BindManageListGrid(string sortby, string direction) { if (Session["ManageList"] != null) { DataTable dtList = Session["ManageList"] as DataTable; if (dtList.Rows.Count > 0) { DataView dv = new DataView(dtList); if (sortby.Length > 0) dv.Sort = sortby + direction; Session["ManageList"] = dv.ToTable(); gvManageList.DataSource = dv.ToTable(); gvManageList.DataBind(); } else { Session["ManageList"] = null; } } }
Monday, December 16, 2013
How to sort the gridview data ASP.Net?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment