Using DetailsView control to add record to Child
I have two tables in a parent, child relationship. Each has a Primary Key ID and the child has the Primary Key of the parent as a Foreign Key.
Table = Worksites, Primary Key = keyWorksitesID
Table = JobTitles, Primary Key = keyJobTitlesID, Foreign Key = keyWorksitesID
On an ASP.Net 2.0 Web Form I have a GridView2 databound to Worksites and a GridView3 databound to JobTitles and a DetailsView1 bound to the Selected Row of GridView3 so that when I Select a Worksites record in GridView2, GridView3 displays all the child JobTitles of the selected Worksite. Then when I select one of the JobTitles in GridView3, DetailsView1 displays that record.
That's all great.
Using the DetailsView1 I can Edit any JobTitle. That's great.
The problem is when I try to Add a New JobTitle using the DetailsView, the new record IS added, but the Foreign Key value, keyWorksitesID, is NULL. Everything else is added fine; new record with PK and the rest of the columns, but the keyWorksitesID, FK, column is NULL.
How would I get the new record to pull the keyWorksitesID value from that field in the selected record of the GridView3?
The New record will always have the same keyWorksitesID, foreign key, as the record selected in the GridView3. I'm trying to add a new child to the same parent as the selected record.
Thanks for any help. BTW, I am a beginner programmer, so example code is very helpful.
|All times are GMT -4. The time now is 09:40 PM.|
Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.