DataSet Sorting Issue

Discussion in 'ASP .Net' started by kaczmar2@hotmail.com, Mar 15, 2005.

  1. Guest

    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.
    , Mar 15, 2005
    #1
    1. Advertising

  2. 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.

    <> wrote in message
    news:...
    >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.
    >
    Kevin Spencer, Mar 15, 2005
    #2
    1. Advertising

  3. On Tue, 15 Mar 2005 15:57:45 -0600, <> wrote:

    > 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;


    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Mar 15, 2005
    #3
  4. Guest

    Thank you, that was my problem. I will be more careful next time!
    , Mar 15, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Dutoit

    Re: Sorting on a disconnected dataset

    Justin Dutoit, Aug 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    585
  2. Replies:
    2
    Views:
    1,406
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    372
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    464
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    139
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page