|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Easy way to use bound combo with foreignkey id/value on webform?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. 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() Show quoteHide quote "Adjo" wrote: > 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. > > |
|||||||||||||||||||||||