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
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