How to set value and label to a DropDownList?

  • Thread starter Robson Carvalho Machado
  • Start date
R

Robson Carvalho Machado

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)
 
J

Jos

Robson said:
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"))
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top