Solved

Dataview sort

Posted on 2014-02-06
4
439 Views
Last Modified: 2014-02-06
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

0
Comment
Question by:runnerjp2005
  • 2
4 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
Comment Utility
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";
0
 

Author Comment

by:runnerjp2005
Comment Utility
Hi thanks but the issue is between the numbers 45 & 46 is the letters HT - also after 90 is FT
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
You can keep an integer column with 1 to 90, sort it and then insert HT and FT afterwards.
0
 

Author Closing Comment

by:runnerjp2005
Comment Utility
That would do it!

thanks :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now