Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to sort a DataSet on a Drop Down Box 1

Status
Not open for further replies.

1Data

MIS
Sep 30, 2005
66
US
Can someone please help me sort a drop down box DataSet. I have read that you have to use a DataView. I have tried that and can't get it to work.

Thanks in advance
 
All you need to do is place the relevant table from the dataset into a dataview, and then call the Sort method of the DataView with the name of the column to sort by e.g.
Code:
MyDataView.Sort = "myColumn DESC"


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I just read where you cant sort drop down box's thanks anyway going to have to do with my SPROC...

 
I just read where you cant sort drop down box's
What do you mean you can't sort drop down lists? My above example shows you how to do it with a DataView...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
You can sort a DropDownList and I've shown you how to do it...I don't know what else to say, apart from repeat what I said above which is to use a DataView.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I just had a wild idea... maybe you could try using a DataView.

 
I thought there were professionals on these forums...I could do without the scarcasm Sheco..I figured it out..from what I can read most people offer suggestions not commands.
 
Sheco was simply pointing out the fact that I had said 3 times in my 3 posts that it was very easy to do with a DataView, yet you seemed to be ignoring my suggestions and even stated that it couldn't be done even though I had given you an example which proved it could be done.

If you had taken my suggestion after my first post and tried it out, you would have saved a lot of time (especially as you then went onto trying completely different approaches in thread855-1140400). Also, it would be more beneficial to other users who read this thread in the future, if you gave something back to them (i.e. how you "figured it out") so they don't have to go through the same thing. To save you the trouble of doing it this time, here's a really simple example:

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        ' Declarations
        Dim dt As New DataTable
        Dim dr As DataRow
        Dim rndNo As Integer

        ' Create a datatable with ten sample records
        dt.Columns.Add("Item1")
        For i As Integer = 1 To 10
            dr = dt.NewRow
            Randomize()
            rndNo = Int((10 - 1 + 1) * Rnd())
            dr("Item1") = CStr(i * rndNo).PadLeft(3, "000")
            dt.Rows.Add(dr)
        Next

        ' Create a DataView to sort the random numbers
        Dim dv As New DataView
        dv = dt.DefaultView
        dv.Sort = "Item1 DESC"

        ' Bind the DropDownList to the DataTable
        DropDownList1.DataTextField = "Item1"
        DropDownList1.DataValueField = "Item1"
        DropDownList1.DataSource = dv
        DropDownList1.DataBind()

    End Sub

Now, when you run the above code you'll see that the DropDownList is sorted, whereas, if you hadn't created the DataView and just used the DataTable, it would not have been sorted.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Have a star for your perseverance... and good answer.

Hope everyone is having a great day!

Thanks - Jennifer
 
Thanks Jennifer!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top