DataSet Sorting Issue

K

kaczmar2

I have the following code, which
1) grabs data from a database
2) appends a data row to the data set
3) sorts the data

I cannot get the data to sort. Everything is working fine
execeptDefaultView.Sort method is inneffective. The code is below:

' rbl = RadioButtonList
ds = CreateDataSource() ' returns a dataset
' Add N/A option
drRow = ds.Tables("Accessories").NewRow
drRow.Item("AccessoryID") = -1
drRow.Item("Accessory") = "N/A"
ds.Tables("Accessories").Rows.Add(drRow)
ds.Tables("Accessories").DefaultView.Sort = "AccessoryID"

rbl.DataSource = ds
rbl.DataMember = "Accessories"
rbl.DataTextField = "Accessory"
rbl.DataValueField = "AccessoryID"
rbl.DataBind()
rbl.SelectedIndex = 0

Everything is working but the sorting. I need it to sort by ID, since
I add a "N/A" option with ID of -1, and then select the first index of
the control.

Any tips would be appreciated.
 
K

Kevin Spencer

You're not binding to the sorted DataView. You're binding to the DataSet
itself.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
C

Craig Deelsnyder

I have the following code, which
1) grabs data from a database
2) appends a data row to the data set
3) sorts the data

I cannot get the data to sort. Everything is working fine
execeptDefaultView.Sort method is inneffective. The code is below:

' rbl = RadioButtonList
ds = CreateDataSource() ' returns a dataset
' Add N/A option
drRow = ds.Tables("Accessories").NewRow
drRow.Item("AccessoryID") = -1
drRow.Item("Accessory") = "N/A"
ds.Tables("Accessories").Rows.Add(drRow)
ds.Tables("Accessories").DefaultView.Sort = "AccessoryID"

rbl.DataSource = ds
rbl.DataMember = "Accessories"
rbl.DataTextField = "Accessory"
rbl.DataValueField = "AccessoryID"
rbl.DataBind()
rbl.SelectedIndex = 0

Everything is working but the sorting. I need it to sort by ID, since
I add a "N/A" option with ID of -1, and then select the first index of
the control.

Any tips would be appreciated.

Try setting

rb1.DataSource = ds.Tables("Accessories").DefaultView;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top