Displaying foreign key data

R

Richard Carpenter

I understand how to use a dropdown list control to display the
associated description value for a foreign key in a parent rather than
the key itself, but I don't like having to disable the control when I
want to prevent editing (simply displaying in the display template of a
datalist or detailview control, for example). I've not been able to
find a way to edit the disabled color of the dropdown list, so it
appears very washed out - just not a good look and doesn't make much
sense to the user.

Is there a way to bind a text box to the description field in a lookup
table? If I'm showing a list of orders, I really don't want to display
the surrogate key value to denote the customer. I would rather display
the customer's name from the Customers table.

Rich
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Make a join in the query when you are fetching the data.

Example:

select a.this, a.that, c.CompanyName
from Article a
inner join Company c on c.CompanyId = a.CompanyId
 
R

Richard Carpenter

Well, I had considered that, but does that cause a problem in, for
example, a formview control? If I bind a textbox to the CompanyName in
the itemview template and a dropdown list control to the CompanyID in
the edit and insert templates, what will I need to do to ensure that
the itemview template displays the correct value after an edit or
insert? Anything?

Rich
 
R

Richard Carpenter

Well, I was thinking I'd get an answer to this question and understand
what I was in for before changing too much of the code, but I decided
to bite the bullet and just try it. I was pleasantly surprised to find
that when changes are made to a foreign key field using a dropdown list
in the edititem template of my formview control, they are, in fact,
reflected in the itemview template textbox. That tells me that the data
is re-queried when the changes are saved. This is a good thing in that
respect.

The downside, for my application anyway, is that also means that child
records that are displayed in a grid on the same page will also be
written to the database upon saving. How might I roll back the addition
of new child records in the event the user cancels the edit operation
on the parent?

For instance, if a user clicks the New button in my formview control to
add a new parent record and in the process adds a couple of child
records, then decides to cancel the insert process on the parent, what
happens with the newly-created child records? How can I avoid those
records being written to the database until the parent record is saved?

I have another post dedicated to this question. Answers may be more
appropriately directed there.

Thanks!
Rich
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top