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

Setting DataValueField for dropdownlist item

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
Hi All,

I have a dropdownlist that I need to add an item to. I have the text & value for this item, but do not know how to set the DataValueField.

Here is how I am adding the item:

drpHRDepartment.Items.Add(objDataReader("strDepartment").ToString())

How do I now set the ID for the department to the DataValueField for this item?

Thanks,
Mark
 
Is this what you are looking for?
Code:
While dr.Read
 With dr
  DropDown.Items.Add( _
    New ListItem(dr("Description"), _
    dr("ID")))

 End With
End While
Hope this helps.
 
Well that's not quite right; you don't need the "With" but you get the idea.
 
I get an error when I try it:

Type 'ListItem' is not defined.

Do I need a specific import and/or declaration?

Thanks,
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top