DetailsView and foreign key and LINQ-to-SQL

C

Craig Buchanan

I am using a DetailsView to add and edit records related to a 'child' table.
The 'child' table has an auto-increment field as its primary key, but it
requires a reference the 'parent' table's primary key to ensure referential
integrity.

If a new child record is to be added, I pass the parent key field to the
page thru a querystring variable. In the Page_Load, I assign the parent key
to the hidden ASP:Textbox that holds the value. I use FindControl to locate
this value.

Obviously, I needed to change the default DetailsView by converting the
bound foreign key to a templated control so the FindControl will work.

This approach mostly works--the record is successfully added to the
database, but I get an error about converting an INT32 to an Object when the
DetailsView is databound.

What am I missing? Is there a more elegant way to do this? Seems like I
should be able to located the bound field programmatically, without having
to create a templated control.

If it makes a difference, I'm using LINQ-to-SQL for the persistence.

Thanks,

Craig Buchanan
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top