Click here to Skip to main content
15,881,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,

DataView dv = ds.Tables[0].DefaultView;
dv.Sort = ViewState["Sort"].ToString();
OR
ds.Tables[0].DefaultView.Sort=ViewState["Sort"].ToString();

when i use first command gridview successfully sorted but the second command the gridview not sorting?

Where i done a mistake, if the code is wrong?
Posted

 
Share this answer
 
v2
Comments
Somasundharam Arjunan 18-Oct-13 3:34am    
Yes am done the same....
here my code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Sort"] = Sort;
bind_gridView();
}
}

public void bind_gridView()
{


DataSet ds = oBAL.bind_Gridview("select");
ViewState["EmployeeDetails"] = ds;
//DataView dv = ds.Tables[0].DefaultView;
//dv.Sort = ViewState["Sort"].ToString();
ds.Tables[0].DefaultView.Sort = ViewState["Sort"].ToString();
GridView1.DataSource = ds;

GridView1.DataBind();
}
Deenuji 18-Oct-13 3:37am    
if (IsPostBack)
{
ViewState["Sort"] = Sort;
bind_gridView();
}
Remove ! in postback and try once:


C#
if (IsPostBack)
            {
                ViewState["Sort"] = Sort;
                bind_gridView();
            }
 
Share this answer
 
I got the Solution :)

ds.Tables[0].DefaultView.Sort = ViewState["Sort"].ToString();
GridView1.DataSource = ds.Tables[0];

Its working me....

Thanks for your comment Deenuji


Thanks and Regards,
Somasundharam Arjunan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900