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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: asp.net code not displaying results
    ... attempting to move from asp classic to the dotnet world. ... and the w3schools site sez it it is asp.net compatibile -- and in fact ... I installed IIS, set up a virtual directory, created an aspx file and ... NOW function -- won't display. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ASP.NET 2.0 Easier than ASP? Gimmie a Break!
    ... grid/table with the results from a query. ... I love asp.net, the possibilities compared to imo flawed asp is much ... database, display a grid/table, and not have much to worry about. ... I've seen a few online examples writing an n-tier design for ASP.NET 2.0 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Let client update a website message
    ... An easier way is to use a backend databased and and and ASP scipt to grba abd display the last entred message. ... Then on the home page Or the page you want to diaplt the massage) inlude ASP script to grab the last enttredred message and display it. ... My client would like to be able to update their 'Weekly Message' on his site. ... I've experimented with guestbook, and few other ways of doing this, but keep coming up with strange field information that would be displayed. ...
    (microsoft.public.frontpage.programming)
  • Re: Displaying Related Data
    ... Actually the bound field is the foreign key field in the main table. ... to display the value which has a matching primary key. ... For data source you need to either find the table ...
    (microsoft.public.vb.general.discussion)
  • Re: Lookup fields in tables bad?
    ... not sure I understand when a foreign key could be a text box, ... Textboxes and combo boxes are display tools. ... A Primary Key is a field - or a set of up to ten fields - which uniquely ... ZIP codes are another reasonable choice. ...
    (microsoft.public.access.tablesdbdesign)