re-ordering ListBox items

Discussion in 'ASP .Net' started by Stimp, Nov 18, 2004.

  1. Stimp

    Stimp Guest

    I have a listbox of values that I populate from a database.

    I want the user to be able to re-order the list
    (by first selecting an item and then clicking 'up' or 'down' buttons)
    and then save the list back to the database.

    First of all, I implemented the re-ordering through client-side
    javascript, which worked great (also it didn't require a postback every
    time an item was re-ordered). For testing purposes, I'm outputting the
    contents of the ListBox collection to a string before I start writing
    back to the database...

    To my disbelief, upon clicking the button to output the ListBox, it only
    output the original order of Items (not the re-ordered version) and
    reloaded the screen back to the original order.

    Obviously this is because the ListBox collection is held in Viewstate
    and the client-side changes are not overwriting these.

    This leads to my first question: is there any way for the client-side
    changes to be written to Viewstate (or written to the ListBox
    collection)??

    Second question:
    Alternatively, I could create a comma-delimited string containing a list
    of the item values in the new order.. but I've not idea how to send this
    back to the server... any ideas?

    Finally, as a last resort I've tried to do this using asp.net server
    controls (using post-back to update the collection everytime an item is
    moved). This is the least-desirable alternative, but leads to my third
    question:
    Is it possible to somehow change the order of items in the ListBox
    collection? I've had no luck finding any links on google.

    Any help on the above is much appreciated,
    Peter
    --

    "I hear ma train a comin'
    .... hear freedom comin"
    Stimp, Nov 18, 2004
    #1
    1. Advertising

  2. 1. Sorry, don't know of one.

    2. Try storing your string in a hidden field.

    3. Agreed this would be an annoying solution for the user, but in a pinch
    probably pretty easy: on the postback, take the value of selectedindex,
    decide up/down based on the button, then swap text and value of the two
    listitems affected, e.g. listbox.items(selectedindex).text =
    listbox.items(selectedindex+1).text, etc.

    hth,

    Bill

    "Stimp" wrote:

    > I have a listbox of values that I populate from a database.
    >
    > I want the user to be able to re-order the list
    > (by first selecting an item and then clicking 'up' or 'down' buttons)
    > and then save the list back to the database.
    >
    > First of all, I implemented the re-ordering through client-side
    > javascript, which worked great (also it didn't require a postback every
    > time an item was re-ordered). For testing purposes, I'm outputting the
    > contents of the ListBox collection to a string before I start writing
    > back to the database...
    >
    > To my disbelief, upon clicking the button to output the ListBox, it only
    > output the original order of Items (not the re-ordered version) and
    > reloaded the screen back to the original order.
    >
    > Obviously this is because the ListBox collection is held in Viewstate
    > and the client-side changes are not overwriting these.
    >
    > This leads to my first question: is there any way for the client-side
    > changes to be written to Viewstate (or written to the ListBox
    > collection)??
    >
    > Second question:
    > Alternatively, I could create a comma-delimited string containing a list
    > of the item values in the new order.. but I've not idea how to send this
    > back to the server... any ideas?
    >
    > Finally, as a last resort I've tried to do this using asp.net server
    > controls (using post-back to update the collection everytime an item is
    > moved). This is the least-desirable alternative, but leads to my third
    > question:
    > Is it possible to somehow change the order of items in the ListBox
    > collection? I've had no luck finding any links on google.
    >
    > Any help on the above is much appreciated,
    > Peter
    > --
    >
    > "I hear ma train a comin'
    > .... hear freedom comin"
    >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 18, 2004
    #2
    1. Advertising

  3. Stimp

    Stimp Guest

    On Thu, 18 Nov 2004 Bill Borg <> wrote:
    > 1. Sorry, don't know of one.
    >
    >>
    >> This leads to my first question: is there any way for the client-side
    >> changes to be written to Viewstate (or written to the ListBox
    >> collection)??


    What about using the IPostBackDataHandler interface?
    Apparently this tests if the current state is different to that in
    Viewstate and, if so, will update the ViewState accordingly..

    reading about it now...

    http://www.netomatix.com/updowncontrol.aspx

    Anybody here used this interface, or even if it's right for what I'm
    trying to do?

    Thanks,
    Peter
    --

    "I hear ma train a comin'
    .... hear freedom comin"
    Stimp, Nov 19, 2004
    #3
  4. Stimp

    Stimp Guest

    On Fri, 19 Nov 2004 Stimp <> wrote:
    > On Thu, 18 Nov 2004 Bill Borg <> wrote:
    >> 1. Sorry, don't know of one.
    >>
    >>>
    >>> This leads to my first question: is there any way for the client-side
    >>> changes to be written to Viewstate (or written to the ListBox
    >>> collection)??

    >
    > What about using the IPostBackDataHandler interface?
    > Apparently this tests if the current state is different to that in
    > Viewstate and, if so, will update the ViewState accordingly..
    >
    > reading about it now...
    >
    > http://www.netomatix.com/updowncontrol.aspx
    >
    > Anybody here used this interface, or even if it's right for what I'm
    > trying to do?


    I figured it out using a hidden field and Viewstate.

    And no postback.. yay me :)

    Thanks again for the help
    --

    "I hear ma train a comin'
    .... hear freedom comin"
    Stimp, Nov 19, 2004
    #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. kent
    Replies:
    1
    Views:
    866
    Andrew de la Harpe
    May 3, 2004
  2. =?Utf-8?B?RGlnZ2xlcg==?=

    Ordering items in ListBox

    =?Utf-8?B?RGlnZ2xlcg==?=, May 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    503
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    May 4, 2004
  3. K B
    Replies:
    2
    Views:
    657
  4. Tomas
    Replies:
    1
    Views:
    563
    Munna
    Aug 12, 2008
  5. nbigaouette

    Z-Ordering (Morton ordering) question

    nbigaouette, Nov 5, 2009, in forum: C Programming
    Replies:
    2
    Views:
    2,095
Loading...

Share This Page