Ordering items in ListBox

G

Guest

I have a group of items in the database that need to be sorted by the client. There is a field in the database that stores the desired order (0, 1, 2, etc...). I would like to allow the client to move the ListBox.Items up and down in the ListBox via JavaScript and then, on the form submit, read the items in the ListBox from the client IN ORDER so I can save the changes in position into the database.

Unfortunately, the server is unaware of the changes in the ListBox. While in the 'for' loop, it remembers from server memory the original order rather than actually read them from the client.

Is there any way to read the actual order of the items from the client?
 
P

Peter O'Reilly

The biggest task is reconstructing the list box from scratch each time the
user moves an item up or down using client side JavaScript. This is no small
order, but it is very possible to do.

Specifically, there is no index to adjust with the HTML select input list
box. You must dump the contents into an array, clear the list box and then
repopulate the list box with list items. Each listbox item has a value and
a display text property. Set the value property to the desired list order
index which will then be used by your server side executing code.

Remember it's HTML, it's light weight and following w3c specifications.
Unlike say a rich client windows forms application, much of the creative
coding is left up to you -in this case an HTML select input. Good luck.
 
G

Guest

Hi

ListBox is only supposed submit selection to server not the order. You might need to add a hidden field(runat server) and store the client changed order like "3,2,4,1". Then you can handle it on server

Bin Song, MCP
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top