Easy way to use bound combo with foreignkey id/value on webform?

A

Adjo

Okay, I've seen all the examples of using comboboxes on webforms when
using simple values. And in the issue-tracker starterkit there is a way
to use comboboxes with id/value foreign keys in a smart (but hard!)
way.
I think every developer needs bound comboboxes to store foreign
keyvalues while displaying the user-friendly value as it is stored in
the foreign table, so there must be plenty of you that have found a way
to do so...
In a windows form databinding the combo together with using the
DataTextField and DataValueField works. Still not very easy I think but
ok...
Now in a webform I cannot manage to make this work. Still don't know
for sure if this is the easyest way. Found a number of examples on the
Net, but most of the time I think they use too much code. I just need a
simple (quickanddirty way if you want...) to use a bound combo with a
foreign key in it... I did not look to VisualStudio2005 yet, but there
must be a way it can be done in 2003 as well I suppose?

I've had enough of searching for the ultimate example, so please help
if you can.
 
G

Guest

You didn't specify where your data is coming from below uses a SqlDataReader,
ddlTest is a dropdownlist on the web page:

Dim rdr As SqlClient.SqlDataReader =
MyProject.Data.Utilities.GetDataReader("Select ID, Description From
TableName")
ddlTest.DataTextField = "Description"
ddlTest.DataValueField = "ID"
ddlTest.DataSource = rdr
ddlTest.DataBind()
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top