How to display Foreign-Key Name fields in edit mode of data contro

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9uYXRoYW4gTC4=?=, Aug 26, 2005.

  1. I've got a relatively simple scenario that I haven't been able to solve in
    ASP 2.0.

    Let's assume I have a simple foreign key relationship as demonstrated below:

    ------------------- -----------------------------
    | States | | Customers |
    ------------------- ----------------------------
    | ID | Name | | ID | Name | Location |
    -------------------- -----------------------------
    | 1 | Alabama | | 1 | Bob | 3 |
    | 2 | Alaska | | 2 | Joe | 2 |
    | 3 | Arizona | | 3 | Jill | 1 |
    | n | ... | | n | .... | ... |
    -------------------- -----------------------------

    Now, let's assume I want a webform to display (or allow editing) a list of
    customers with a DataGrid or similar control.

    I have NOT been able to figure out a way in ASP 2.0 to have the name field
    in the foreign key table to display the state name.
    For viewing, this is easily overcome by designing a query that contains
    performs the appropriate join and then display that column... but what if I
    want to edit?

    In edit mode, I would still like to display the state name (in a
    DropDownList of all states) and use that in performing the edit/update. I
    can't find a way to do this.

    In ASP 1.1 this way relatively easy - You could use a DataList and bind the
    List to an SQLDataAdapter containing the "Customers" table and have a second
    SQLDataAdapter containing the States table. For the DropDownList in edit
    mode, you could override the default binding and bind the DataTextField and
    DataValueField properties seperately to the full list of states in the second
    SQLDataAdapter.

    This should be an incredibly common and simple task - displaying a lookup
    for a foreign key - but I haven't gotten it to work vis-a-vis editing data,
    and this has been embarassing.

    Any help or suggested links are appreciated.

    - Jonathan
     
    =?Utf-8?B?Sm9uYXRoYW4gTC4=?=, Aug 26, 2005
    #1
    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. H5N1
    Replies:
    0
    Views:
    473
  2. Richard Carpenter

    Displaying foreign key data

    Richard Carpenter, Jul 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    677
    Richard Carpenter
    Jul 10, 2006
  3. Pete Hurst
    Replies:
    3
    Views:
    2,800
    Pete Hurst
    Aug 7, 2009
  4. Lionel
    Replies:
    9
    Views:
    3,515
  5. Bryon Brewer

    Datagrid - foreign key values - replace ID with name

    Bryon Brewer, Jul 26, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    285
    Bryon Brewer
    Jul 26, 2003
Loading...

Share This Page