chandu gummadi

chandu gummadi

  • NA
  • 67
  • 71.6k

gridview sorting in asp.net using c#

Apr 8 2013 3:39 AM
HI friends iam developing grid view sorting application in asp .net.
iam writting bellow code but its not working properly.

grid view sorting is done for one column and sorting is not done for another column it shows error like  "INVALID COLUMN EMPNAME"

PLEASE SOLVE MY PROBLEM.

public void BindGVPasswordChange()
    {

        try
        {
            DataTable dt = new DataTable();
            Hashtable htnew = new Hashtable();
            htnew.Add("PwdId", 0);
            dt = _sec.getDataTable("Stp_UM_FillGV_Changepasswords", CommandType.StoredProcedure, htnew);
            if (dt.Rows.Count > 0)
            {
                DataView dv = dt.DefaultView;
                if (ViewState["SortDirection"] != null)
                {
                    sortDirection = ViewState["SortDirection"].ToString();
                }
                if (ViewState["SortExpression"] != null)
                {
                    sortExpression = ViewState["SortExpression"].ToString();
                    dv.Sort = string.Concat(sortExpression, " ", sortDirection);
                }
                GVChangePwd.DataSource = dv;
                GVChangePwd.DataBind();
               
            }

            GVChangePwd.Visible = true;
        }
        catch (Exception ex)
        {
        }
       
    }


protected void GVChangePwd_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (ViewState["SortDirection"] == null || ViewState["SortExpression"].ToString() != e.SortExpression)
        {
            ViewState["SortDirection"] = "ASC";
            GVChangePwd.PageIndex = 0;
        }
        else if (ViewState["SortDirection"].ToString() == "ASC")
        {
            ViewState["SortDirection"] = "DESC";
        }
        else if (ViewState["SortDirection"].ToString() == "DESC")
        {
            ViewState["SortDirection"] = "ASC";
        }
        ViewState["SortExpression"] = e.SortExpression;
        BindGVPasswordChange();
 
    }

Answers (1)