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

Discussion in 'ASP .Net Web Controls' started by Adjo, Jun 22, 2005.

  1. Adjo

    Adjo Guest

    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.
     
    Adjo, Jun 22, 2005
    #1
    1. Advertising

  2. Adjo

    Harolds 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()


    "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.
    >
    >
     
    Harolds, Jun 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GMK

    foreignKey constraint error.

    GMK, Mar 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Mar 11, 2005
  2. Adjo
    Replies:
    1
    Views:
    359
    =?Utf-8?B?SGFyb2xkcw==?=
    Jun 22, 2005
  3. Phillip Vong
    Replies:
    0
    Views:
    418
    Phillip Vong
    Jul 27, 2006
  4. grz01
    Replies:
    0
    Views:
    2,567
    grz01
    Nov 17, 2009
  5. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    598
    Bob Barrows [MVP]
    Nov 16, 2005
Loading...

Share This Page