Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to set value and label to a DropDownList?

Reply
Thread Tools

How to set value and label to a DropDownList?

 
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-12-2004
Dear Friends,

Using HTML we can create a DropDownList as follows

<select name="xxx">
<option value="1">Brazil
<option value="2">USA
<option value="3">Canada
</select>

How can I do this with WebControls by using CodeBehind?

I was trying the below code but could not set both value and label of each
item.

myDropDownList = New DropDownList
myDropDownList.ID = Id
myDropDownList.Items.Add("Brasil")
myDropDownList.Items.Add("USA")
myDropDownList.Items.Add("Canada")
myUnits = New System.Web.UI.WebControls.Unit(402)
myDropDownList.Width = myUnits
myDropDownList.Attributes("style") = Style
PlaceHolder1.Controls.Add(myDropDownList)


 
Reply With Quote
 
 
 
 
Jos
Guest
Posts: n/a
 
      08-13-2004
Robson Carvalho Machado wrote:
> Dear Friends,
>
> Using HTML we can create a DropDownList as follows
>
> <select name="xxx">
> <option value="1">Brazil
> <option value="2">USA
> <option value="3">Canada
> </select>
>
> How can I do this with WebControls by using CodeBehind?
>
> I was trying the below code but could not set both value and label
> of each item.
>
> myDropDownList = New DropDownList
> myDropDownList.ID = Id
> myDropDownList.Items.Add("Brasil")
> myDropDownList.Items.Add("USA")
> myDropDownList.Items.Add("Canada")
> myUnits = New System.Web.UI.WebControls.Unit(402)
> myDropDownList.Width = myUnits
> myDropDownList.Attributes("style") = Style
> PlaceHolder1.Controls.Add(myDropDownList)


myDropDownList.Items.Add(New ListItem("Brasil","1"))
myDropDownList.Items.Add(New ListItem("USA","2"))
myDropDownList.Items.Add(New ListItem("Canada","3"))

--

Jos


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Set Label Value using Javascript chrispragash@hotmail.com ASP .Net 5 03-26-2008 07:53 AM
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
JavaScript assigns a value to label control text value? =?Utf-8?B?ZGF2aWQ=?= ASP .Net 8 05-26-2006 04:20 PM
Getting value from asp:label into javascript input value Dwizz Javascript 10 08-07-2005 02:28 AM



Advertisments