ASP .NET Details view insert with Parent Key
Posted on 2009-04-07
I have an asp .net app that uses a DetailView to show a single record along with a gridview showing related update comments (that are in a one to many relationship with the selected Detail record). The Detail View record and the Comments in the grid are linked by a field called "MasterRecordID". One detail record may have several associated "comments" which are shown in the gridview.
The user needs the ability to add comments associated with the selected Detail record and I know that I cannot just do an insert to the "comments" gridview. I am trying to use an "Add Comment" button that opens a blank detail view of the Comments in Insert mode. There are only 3 fields in this Comments Detail View (MasterRecordID, Date and Comment).
The problem that I have is that the insert Comment detail view opens with all 3 fields blank. I need the MasterRecordID to pre-populate from the selected MasterRecordID so the user doesn't have to type that field in. I have searched the web and found descriptions of custom selection and insert routines which store and use the value of the selected ID. I would think that I need to somehow store the DetailView MasterRecordID value and then use it to populate the MasterRecordID field of the new comment record, but can't quite get there.
Sorry for the long-winded question...thanks in advance.