By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

re-ordering ListBox items

P: n/a
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"
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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"

Nov 18 '05 #2

P: n/a
On Thu, 18 Nov 2004 Bill Borg <Bi******@discussions.microsoft.com> 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"
Nov 18 '05 #3

P: n/a
On Fri, 19 Nov 2004 Stimp <re*@spumco.com> wrote:
On Thu, 18 Nov 2004 Bill Borg <Bi******@discussions.microsoft.com> 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"
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.