Tuesday 17 September 2013

Sorting Of The Gridview column without using Datasource

 protected void GVinsurance_onSorting(object sender, GridViewSortEventArgs e)
        {

            DataTable dt1 = (DataTable)ViewState["DT"];//GVProvider.DataSource as DataTable;
            if (dt1 != null)
            {

                if (dt1 != null)
                {
                    DataView dvSortedView = new DataView(dt1);

                    dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);

                    GVInsurance.DataSource = dvSortedView;
                    GVInsurance.DataBind();
                }

            }
        }

----------------------------------------



 private string getSortDirectionString(SortDirection sortDirection)
        {
            string newSortDirection = String.Empty;

            if (Convert.ToString(ViewState["newSortDirection"]) == "DESC")
            {
                ViewState["newSortDirection"] = "ASC";
            }
            else
                ViewState["newSortDirection"] = "DESC";

            return newSortDirection = Convert.ToString(ViewState["newSortDirection"]);
        }