Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > re-ordering ListBox items

Reply
Thread Tools

re-ordering ListBox items

 
 
Stimp
Guest
Posts: n/a
 
      11-18-2004
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"
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      11-18-2004
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"
>

 
Reply With Quote
 
 
 
 
Stimp
Guest
Posts: n/a
 
      11-19-2004
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"
 
Reply With Quote
 
Stimp
Guest
Posts: n/a
 
      11-19-2004
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy ListBox items to anoher listbox Tomas ASP .Net 1 08-12-2008 08:22 AM
unable to retrieve listbox items on postback , items moved usingjavascript between 2 list boxes (source and target ) divya ASP .Net 1 05-28-2008 05:27 AM
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
add items from one listbox to other listbox from javascript mc Javascript 0 12-02-2003 08:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57