S
Stimp
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 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