p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   ASP.NET 1.x and 2.0 Application Design (http://p2p.wrox.com/asp-net-1-x-2-0-application-design-67/)
-   -   Using DetailsView control to add record to Child (http://p2p.wrox.com/asp-net-1-x-2-0-application-design/70435-using-detailsview-control-add-record-child.html)

megnin September 5th, 2008 03:37 PM

Using DetailsView control to add record to Child
 
Hello,

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.


Thanks,
-David


All times are GMT -4. The time now is 12:03 AM.

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.