Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - How to copy dropdownlist to each other?

Reply
 
Old 12-08-2008   #1 (permalink)
JP


 
 

How to copy dropdownlist to each other?

I need to know how to copy one DropDownList to another in a single line.

I have a class method that builds a DropDownList object at runtime. This
object is then returned to the calling ASPX page. I tried:

dropNames = CommonTools.LoadNames(); //returns DropDownList object

LoadNames returns a populated DropDownList object. But the rendered list is
blank even though the debugger says that the class did return with the
correct object.

The only time I can get the DropDownList to display its content is:

dropNames .DataSource = CommonTools.LoadNames().Items


Even then I get the Text options, but the Values are just the same as the
text and not what the “values” the class returned.


How can I accomplish this? Im trying to avoid a FOREACH


My System SpecsSystem Spec
Old 12-08-2008   #2 (permalink)
Bill Richards


 
 

Re: How to copy dropdownlist to each other?

What possible reason could there be for *needing* to do this in a single
line of code?

"JP" <JP@xxxxxx> wrote in message
news:B3D28738-C6CA-4F15-A171-0B596FCCEF7F@xxxxxx
Quote:

>I need to know how to copy one DropDownList to another in a single line.
>
> I have a class method that builds a DropDownList object at runtime. This
> object is then returned to the calling ASPX page. I tried:
>
> dropNames = CommonTools.LoadNames(); //returns DropDownList object
>
> LoadNames returns a populated DropDownList object. But the rendered list
> is
> blank even though the debugger says that the class did return with the
> correct object.
>
> The only time I can get the DropDownList to display its content is:
>
> dropNames .DataSource = CommonTools.LoadNames().Items
>
>
> Even then I get the Text options, but the Values are just the same as the
> text and not what the “values” the class returned.
>
>
> How can I accomplish this? Im trying to avoid a FOREACH
>
My System SpecsSystem Spec
Old 12-08-2008   #3 (permalink)


Vista Business x64
 
 

Re: How to copy dropdownlist to each other?

For a Winforms App a single line:
comboBox2.DataSource = comboBox1.Items;

For a Web App two lines:
this.DropDownList2.DataSource = this.DropDownList1.Items;
this.DropDownList2.DataBind();

EDIT: oops, never mind, the values are copied as strings equal to the text value in the web app...
My System SpecsSystem Spec
Old 12-08-2008   #4 (permalink)


Vista Business x64
 
 

Re: How to copy dropdownlist to each other?

How's this (4 lines, but no for loop):
this.DropDownList2.DataTextField = "Text";
this.DropDownList2.DataValueField = "Value";

this.DropDownList2.DataSource = this.DropDownList1.Items;
this.DropDownList2.DataBind();

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Add Event Handler to dynamic DropDownList?????? .NET General
dropdownlist databinding problem .NET General
copy-item changing files attributes on network copy failures PowerShell
vista can't copy large files? another XP file-copy bug? Vista General
Issue need your help: How to control combox/dropdownlist in web page? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

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