I have been searching all morning for a demo or example of inserting a record into a child grid in a hierarchical grid to no avail. The odd thing is, that this was working at one point and I am not sure what changed.
It's a fairly simple grid. The problem I am having is that in the InsertCommand method when I extract the values I see the keys of the two columns I am looking for but the values are always null. Any insight as to what I am doing wrong would be greatly appreciated!
My grid:
My insertcommand method
I put a comment in place of where I am actually doing to the insert into the db because I figured it wasn't relevant. When I view the values HashTable in debug mode, after extracting the values. I can see that it has the two datakeys: call_date and call_outcome, but the values are always null....
thanks for any help!
It's a fairly simple grid. The problem I am having is that in the InsertCommand method when I extract the values I see the keys of the two columns I am looking for but the values are always null. Any insight as to what I am doing wrong would be greatly appreciated!
My grid:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnItemCommand
=
"ViewResponse"
OnSortCommand
=
"RadGrid1_SortCommand"
OnPageIndexChanged
=
"RadGrid1_PageIndexChanged"
OnPageSizeChanged
=
"RadGrid1_PageSizeChanged"
Skin
=
"Office2007"
ShowStatusBar
=
"true"
Width
=
"100%"
AllowSorting
=
"True"
AllowPaging
=
"True"
PageSize
=
"20"
OnNeedDataSource
=
"GridNeedsDataSource"
OnPreRender
=
"RadGrid1_PreRender"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
>
<
MasterTableView
DataKeyNames
=
"response_id, survey_id, email_sent_history_id"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"email_sent_history_id"
Name
=
"Calls"
Width
=
"100%"
runat
=
"server"
CommandItemDisplay
=
"Top"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"email_sent_history_id"
MasterKeyField
=
"email_sent_history_id"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridDateTimeColumn
HeaderText
=
"Call Date"
DataField
=
"call_date"
UniqueName
=
"call_date"
PickerType
=
"DatePicker"
>
</
telerik:GridDateTimeColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"Call Outcome"
DataField
=
"call_outcome"
UniqueName
=
"call_outcome"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"email_sent_history_id"
UniqueName
=
"ResponseId"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"response_id"
UniqueName
=
"ResponseId"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
UniqueName
=
"first_name"
DataField
=
"first_name"
HeaderText
=
"First Name"
/>
<
telerik:GridBoundColumn
DataField
=
"last_name"
HeaderText
=
"Last Name"
/>
<
telerik:GridBoundColumn
DataField
=
"organization"
HeaderText
=
"Organization"
/>
<
telerik:GridBoundColumn
DataField
=
"pi_name"
Headertext
=
"PI Name"
/>
<
telerik:GridBoundColumn
DataField
=
"response_date"
DataFormatString
=
"{0:MM/dd/yyyy}"
Headertext
=
"Response Date"
/>
<
telerik:GridBoundColumn
DataField
=
"current_status"
HeaderText
=
"Survey Status"
/>
<
telerik:GridBoundColumn
DataField
=
"score"
Headertext
=
"Score"
/>
<
telerik:GridButtonColumn
UniqueName
=
"Response"
Text
=
"View"
HeaderText
=
"Response"
CommandName
=
"ViewResponse"
/>
<
telerik:GridBoundColumn
DataField
=
"feasibility_status"
HeaderText
=
"feasibility_status"
/>
</
Columns
>
<
PagerStyle
AlwaysVisible
=
"True"
Mode
=
"NextPrevAndNumeric"
Position
=
"TopAndBottom"
></
PagerStyle
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
My insertcommand method
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
if (item == null)
{
return;
}
string errorString = string.Empty;
Hashtable values = new Hashtable();
item.ExtractValues(values);
try
{
var callDate = values["call_date"] == null ? string.Empty : values["call_date"].ToString();
var callOutcome = values["call_outcome"] == null ? string.Empty : values["call_outcome"].ToString();
/*Do some error checking and update the DB if we have values. callDate and callOutcome are always an empty string!*/
}
catch (Exception ex)
{
RadGrid1.Controls.Add(new LiteralControl(string.Format("<
span
style
=
'color:red'
>{0}</
span
>", ex.Message)));
e.Canceled = true;
}
}
I put a comment in place of where I am actually doing to the insert into the db because I figured it wasn't relevant. When I view the values HashTable in debug mode, after extracting the values. I can see that it has the two datakeys: call_date and call_outcome, but the values are always null....
thanks for any help!