Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

How to move items from one listbox to another on a client side?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bogdan - 28 Apr 2008 16:57 GMT
Hi,

I have two listboxes on a page and need to move items between them - using
buttons (e.g. "<<" ">>").  Can this be done on a client side in asp.net?
I'd like to avoid hitting the server on every add/remove.

Thanks,
Bogdan
Cowboy (Gregory A. Beamer) - 28 Apr 2008 17:08 GMT
You can move them using JavaScript, if you wish. You will still have to take
a server trip to commit back to the database, however. A simple example is
here (will not vouch for code, however):

http://www.codeproject.com/KB/aspnet/Listbox_or_combo_box.aspx

Signature

Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************

| Think outside the box!

*************************************************
> Hi,
>
[quoted text clipped - 4 lines]
> Thanks,
> Bogdan
bogdan - 28 Apr 2008 20:26 GMT
Thanks for the reply.  Since I'm rather new to asp.net I think I
miscalculated what I could do on the client side.  I have the code working
moving items between listboxes but have no clue how to pass items of one of
the listboxes back to the server. I could put a 'Save' button that would
post back to the server but I don't know how to pass the new set of items in
the listbox.  The old ones are in the viewstate.  Is there a way to do that?
I might try to select all items on the client side before posting back but
I'm afraid that this might not work because of discrepancies between old
items and selected ones (e.g. selected items were not present in the list
when it was sent to the client).

Any help would be appreciated.

Thanks,
Bogdan

> You can move them using JavaScript, if you wish. You will still have to
> take a server trip to commit back to the database, however. A simple
[quoted text clipped - 12 lines]
>> Thanks,
>> Bogdan
Mark Rae [MVP] - 28 Apr 2008 20:37 GMT
> Thanks for the reply.  Since I'm rather new to asp.net I think I
> miscalculated what I could do on the client side.  I have the code working
[quoted text clipped - 6 lines]
> discrepancies between old items and selected ones (e.g. selected items
> were not present in the list when it was sent to the client).

Client-side changes to the element collection of listboxes are not persisted
across a postback.

Therefore, the "usual" workaround for this is to populate a hidden text box
with as much information as the server-side code needs for its purposes.

E.g. if the "first" listbox contains the following elements:

First
Second
Third
Fourth
Fifth

and it's possible client-side to move any or all of these elements into the
"second" listbox, just before the postback happens (e.g. in the
OnClientClick of a button control) inspect the contents of the "second"
listbox. Let's say that the second listbox now contains the first, third and
fifth elements from the first listbox. Therefore, place the following value
in a hidden text box: "1¬3¬5". This will be posted back to the server along
with the rest of the web form where it will be a simple matter to parse out
the value and identify which of the elements had been moved from the first
listbox to the second.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Mark Rae [MVP] - 28 Apr 2008 17:09 GMT
> I have two listboxes on a page and need to move items between them - using
> buttons (e.g. "<<" ">>").  Can this be done on a client side in asp.net?
> I'd like to avoid hitting the server on every add/remove.

http://www.google.co.uk/search?sourceid=navclient&hl=en-GB&ie=UTF-8&rlz=1T4GZEZ_
en-GBGB252GB252&q=asp%3aListBox+JavaScript+move


Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.