Set unique ID field to drop down list value

gfedz
gfedz used Ask the Experts™
on
I need to populate a drop down list with the text to be the name of 2 columns combined and the value of the text to be the unique ID column.  So intVehicleID column (set as value) and LocationDescription + Vehicle columns (set as the text that corresponds with the intVehicleID).  Right now my code looks like this but does not have the value set.  
sql = "SELECT intVehicleID, LocationDescription, Vehicle FROM VehicleScheduler.dbo.tblVehicles ORDER BY LocationDescription"
        myDataTable = New DataTable
        myDataTable = getData(sql)

        For Each DataRow In myDataTable.Rows
            ddlShow.Items.Add(DataRow("LocationDescription") + " > " + DataRow("Vehicle"))
        Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The ddlShow.items.Add method accepts the Value as a parameter, just pass DataRow("intVehicleID") to it.

Author

Commented:
can you please give me and example?
Commented:
Sorry, it accepts a ListItem object... that object accepts the Text and Value as paramters.

ddlShow.Items.Add(new ListItem(DataRow("LocationDescription") + " > " + DataRow("Vehicle"), DataRow("intVehicleID")))
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
It's giving me an error saying "Overload resolution failed because no accessible 'Add' accepts this number of arguments."

Author

Commented:
Nevermind, my typo.  

Author

Commented:
It gives a value of 7 everytime I change selection..

Commented:
Please view the source on the web page and see if all of them have a value of 7.  If so, the problem is with the database call or the Item collection.  If not (they are different) then the issue is with the callback.

Author

Commented:
I did have to tweak a part of my code but what you gave me made it happen.  Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial