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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP:Dropdownlist

Status
Not open for further replies.

FRANDAZZO

Programmer
Nov 29, 2000
60
US
Hello all, Question:
Is there a way to set the option value tag for the server side <ASP:DropDownList id=&quot;somedropdown&quot;/> ?

This is because when you are in the Page_Load and you populate the dropdowm you can only user the name.items.add(&quot;aaa&quot;). The new addesd item's option will be the same at the display text. I want that old school stuff where the value is different from the display text..

Is this possiable.

Thanks,

Frandazzo
 
Frandazzo,

Yep, you can do as you ask. Consider I have a radiobuttonlist with an id of RBL.

If I bind the RBL to a hash, I can set the DataTextField (which users see) to the key of the hash. The DataValueField (what gets passed), I also set it to the value at that particular key.

RBL.DataSource = theNameOfSomeHash
RBL.DataTextField = &quot;Key&quot;
RBL.DataValueField = &quot;Value&quot;

You can set each of these also to data you pull from a database. You just set your DataSource to something like a DataReader and the DataTextField to some column and the DataValueField to the same or different column in the database. That should get you what you need.

Mike
 
Thanks for the Feedback. But I do not want to do data binding. And as far as asp:DropdownLists, no DataTextField or DataValueField properties. What shall we do? Is there some sort of Index value?

Thanks,

Frandazzo
 
Hey Frand,

You can still do what Motte suggested, just not with the databinding.

Each asp drop down list has .text and a .value property. Check out my code snippit:
With ddlDropDown
.Items.Add(&quot;NewEntry&quot;)
.Items(0).Value = 1
.Items.Add(&quot;NextEntry&quot;)
.items(1).Value = 2
.Items.Add(&quot;ThirdEntry&quot;)
.Items(2).Value = 3
End With

With data binding, you'd be able to also loop through a dataset and fill it, but if yu just want to hardcode it, this is an option.

Let me know if you need anything else,

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top