Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net Dropdown list

Status
Not open for further replies.

FRANDAZZO

Programmer
Nov 29, 2000
60
US
Hello All,

I am making the conversion to ASP.Net.....

Anyway, I have a question about the dropdown lists. When populating a dropdown list and programming in ASP you were able to populate a dropdown list with the following ASP code for the value and display text:
Ex:
<select name=&quot;Name&quot;>
<%For i = 0 to 10%>
<option value=&quot;<%=i%>&quot;>The Display Text</option>
<%Next%>
</select>

Now I know that you can do the same in ASP.Net by databinding and setting the Value and Text properties.

The question is what if I do not want to used databinding. I do not see how you can set the value property....

Please help!

Thankx in advance,

Frandazzo
 
Yup, you can do it, and pretty much the same way

Dim i as integer

For i = 0 to 10
ddlDropDown.items.add(&quot;DisplayText&quot;)
ddlDropDown.Items(i).value = TheValue
Next

Its a 1-2 punch: i will always be the index of the newly added item, therefore you'll always assign the value to the proper display text.

Now, if you want the ddl to display for a specific value once its loaded, you can do this also after the code has run:

ddlDetailListType.Items.FindByValue(Value).Selected = True

Easier than comparing each item being added during the loop.

hth
:)

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top