Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
Hi,

Dataview Sorting is not applied to the following code.
dvSpeed.sort="Service_speed ASC";

the datatype is Integer for the Column Service_speed.
Posted
Updated 13-Apr-11 21:38pm
v3

I have Tried this and its Working Fine
DataTable dt = null;
            DataRow dr = null;

            DataColumn idCoulumn = null;
            DataColumn nameCoulumn = null;
            DataColumn Description  = null;
            //int i = 0;

            dt = new DataTable();
            idCoulumn = new DataColumn("ID", Type.GetType("System.Int32"));
            nameCoulumn = new DataColumn("Name", Type.GetType("System.String"));
            Description = new DataColumn("Description",Type.GetType("System.String"));

            dt.Columns.Add(idCoulumn);
            dt.Columns.Add(nameCoulumn);
            dt.Columns.Add(Description);

            dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Name"] = "Name1";
            dr["Description"]="Good";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["ID"] = 2;
            dr["Name"] = "Name2";
            dr["Description"] = "VeryGood";
            dt.Rows.Add(dr);
            DataView dv = new DataView(dt);
            dv.Sort = "ID DESC";
 
Share this answer
 
Comments
Dalek Dave 14-Apr-11 3:38am    
Good Answer.
Mahendra.p25 14-Apr-11 3:40am    
Thanks
Is Service_spee the Dataview column name as well.
Maybe the column name is different from this value.
 
Share this answer
 
IF you're using a DataGrid to display the result, you must include this after sorting.

MIDL
gridView.DataSource = dvSpeed;
gridView.DataBind();
 
Share this answer
 
Comments
Vinodh.B 14-Apr-11 3:18am    
No i just want to do some calulations after sorting but Sorting itself not done
Pong D. Panda 14-Apr-11 3:20am    
if you can post the other code, it will help.
Vinodh.B 14-Apr-11 3:23am    
Dataview dvSpeed= dtSpeedAndFeed.DefaultView;
dvspeed.sort="Service_Speed ASC";
Now when i check dvspeed its not sorted .
The following code gave the Solution

Dataview dvSpeed=new dataview(dtSpeedAndFeed);

Thanks all for the response .
 
Share this answer
 
Comments
Mahendra.p25 14-Apr-11 3:45am    
You need to accept solution if it works fine

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