Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

Dataview sort

Hi,

How can i sort my column(dv.Row.Item("Time")) in dataview so the output would be sorted like this (Note where the dots are is just continues numbers going up)

0
1
2
3
4
5
6
7
8
9
..........
43
44
45
HT
46
47
48
49
..........
87
88
89
90
FT

Dim DvTheData As New DataView(scorestable)
        'loop through them all and show them
        For Each dv As DataRowView In DvTheData

	test.Text += dv.Row.Item("Time") & " " & dv.Row.Item("Score") &  "<br>"

        Next

Open in new window

Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

hi.. you can use sort function like this..
private DataTable getsortedtable(DataTable dt)
 {
    dataview v=dt.defaultview;
    v.sort="columnName DESC";
    dt=v.toTable();
    return dt;
  }

or make a code like this example

DataTable dt = null;
            DataRow dr = null;
 
            DataColumn idCoulumn = null;
            DataColumn nameCoulumn = null;
            DataColumn Description  = null;
            //int i = 0;

            dt = new DataTable();
            id = new DataColumn("ID", Type.GetType("System.Int32"));
            name = new DataColumn("Name", Type.GetType("System.String"));
            Description = new DataColumn("Description",Type.GetType("System.String"));
 
            dt.Columns.Add(id);
            dt.Columns.Add(name);
            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";
Avatar of Member_2_5230414
Member_2_5230414

ASKER

Hi thanks but the issue is between the numbers 45 & 46 is the letters HT - also after 90 is FT
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That would do it!

thanks :)