Thanks.
<
telerik:GridButtonColumn
ConfirmText
=
"Unassign this contract?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Unassign"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Unassign"
UniqueName
=
"UnassignColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
protected void RadGridDetail_DeleteCommand(object source, GridCommandEventArgs e)
{
//Get the GridDataItem of the RadGrid
GridDataItem item = (GridDataItem)e.Item;
//Get the primary key value using the DataKeyValue.
int locNbr = Convert.ToInt32(RadGridLOC.SelectedValues["in_loc"].ToString());
int locYr = Convert.ToInt32(RadGridLOC.SelectedValues["y_loc"].ToString());
int locVer = Convert.ToInt32(RadGridLOC.SelectedValues["in_loc_version"].ToString());
string CntNbr = item.OwnerTableView.DataKeyValues[item.ItemIndex]["ic_contract"].ToString();
int UwYr = Int32.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex]["y_underwriting"].ToString());
OleDbConnection dbCon = new OleDbConnection(rootWebConfig.ConnectionStrings.ConnectionStrings["ConnectionString"].ToString());
try
{
dbCon.Open();
OleDbCommand cmd = new OleDbCommand("sp_gloc_detail_del_1", dbCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@in_loc", OleDbType.Integer).Value = locNbr;
cmd.Parameters.Add("@y_loc", OleDbType.Integer).Value = locYr;
cmd.Parameters.Add("@in_loc_version", OleDbType.Integer).Value = locVer;
cmd.Parameters.Add("@ic_contract", OleDbType.Char, 11).Value = CntNbr;
cmd.Parameters.Add("@y_underwriting", OleDbType.Integer).Value = UwYr;
cmd.Parameters.Add("@ic_user", OleDbType.Char).Value = Session["GRSUserID"];
cmd.Parameters.Add("@f_mode", OleDbType.Integer).Value = Session["AuthMode"];
cmd.ExecuteNonQuery();
RadGridLOC.Rebind();
//RadGridLOC.MasterTableView.Items[0].Selected = true;
//RadGridLOC.SelectedIndexes.Add(0);
RadGridDetail.SelectedIndexes.Add(0);
}
catch (OleDbException ex)
{
ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "alert('Unable to unassign contract. Please contact System Administrator.');", true);
LogErrorClass errclass = new LogErrorClass();
int i = errclass.LogErrorMsg("Error", ex.Message, ex.StackTrace.ToString(), Session["GRSUserID"].ToString());
e.Canceled = true;
}
finally
{
dbCon.Close();
}
}
9 Answers, 1 is accepted

If your requirement is to persist the expanded state of parent grid after delete operation, you can try the following approach to achieve this.
CS:
public
static
int
rowIndex = -1;
protected
void
RadGridDetail_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
//your code to delete teh item
RadGrid grid = (RadGrid)sender;
GridNestedViewItem nestedItem = (GridNestedViewItem)grid.NamingContainer;
GridDataItem parentItem = (GridDataItem)nestedItem.ParentItem;
rowIndex = parentItem.ItemIndex;
//row index of parent item
RadGridLOC.Rebind();
}
protected
void
RadGridLOC_PreRender(
object
sender, EventArgs e)
{
if
(rowIndex > -1)
{
GridDataItem masterTableItem = (GridDataItem)RadGrid1.MasterTableView.Items[rowIndex];
// Get the mastertable item
masterTableItem.Expanded =
true
;
// Expand the item
rowIndex = -1;
}
}
Thanks,
Princy.

"Unable to cast object of type 'System.Web.UI.WebControls.ContentPlaceHolder' to type 'Telerik.Web.UI.GridNestedViewItem'."
on this line of code:
GridNestedViewItem nestedItem = (GridNestedViewItem)grid.NamingContainer;
Thanks again.

http://www.telerik.com/help/aspnet-ajax/grid-related-grids.html
So perhaps, GridNestedViewItem doesn't really apply to my grids???
If it helps, here is my grids markup (you may see some irrelevant code as I'm trying to do a few other things), it will give you an idea as to how my grids are setup. Thanks.
<
strong
>LOC Header</
strong
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridLOC"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridLOC"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridDetail"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadFilter
runat
=
"server"
ID
=
"RadFilterRGridLOC"
FilterContainerID
=
"RadGridLOC"
ShowApplyButton
=
"true"
ApplyButtonText
=
"Apply Filter"
Skin
=
"Web20"
/>
<
br
/>
<
asp:CheckBox
ID
=
"CheckBoxShowHistory"
runat
=
"server"
AutoPostBack
=
"true"
Text
=
"Show History"
OnCheckedChanged
=
"CheckBoxShowHistory_CheckedChanged"
/>
<
telerik:RadGrid
ID
=
"RadGridLOC"
runat
=
"server"
GridLines
=
"None"
AllowSorting
=
"True"
AllowFilteringByColumn
=
"true"
AllowPaging
=
"true"
AutoGenerateColumns
=
"False"
PageSize
=
"20"
Skin
=
"Web20"
DataSourceID
=
"SqlDataSource1"
Width
=
"95%"
OnItemDataBound
=
"RadGridLOC_ItemDataBound"
OnPreRender
=
"RadGridLOC_PreRender"
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
DataKeyNames
=
"in_loc,y_loc,in_loc_version,c_loc_status,v_comment,n_beneficiary,n_facility,a_loc_total_booked"
IsFilterItemExpanded
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"n_facility"
AllowFiltering
=
"true"
HeaderText
=
"Facility"
UniqueName
=
"n_facility"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_beneficiary"
AllowFiltering
=
"true"
HeaderText
=
"Beneficiary"
UniqueName
=
"n_beneficiary"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"c_loc_status"
AllowFiltering
=
"true"
UniqueName
=
"c_loc_status"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_loc_status"
AllowFiltering
=
"true"
HeaderText
=
"Status"
UniqueName
=
"n_loc_status"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"a_loc_total_booked"
AllowFiltering
=
"true"
HeaderText
=
"Amount"
UniqueName
=
"a_loc_total_booked"
DataFormatString
=
"{0:N0}"
ItemStyle-HorizontalAlign
=
"Right"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"cr_loc"
AllowFiltering
=
"true"
HeaderText
=
"LOC Ccy"
UniqueName
=
"cr_loc"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"in_loc"
AllowFiltering
=
"true"
HeaderText
=
"LOC #"
UniqueName
=
"in_loc"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"y_loc"
AllowFiltering
=
"true"
UniqueName
=
"y_loc"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"in_loc_version"
AllowFiltering
=
"true"
HeaderText
=
"LOC Ver"
UniqueName
=
"in_loc_version"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"d_loc_effective"
AllowFiltering
=
"true"
HeaderText
=
"Issued/Effective Date"
UniqueName
=
"d_loc_effective"
DataFormatString
=
"{0:d}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"d_loc_expire"
AllowFiltering
=
"true"
HeaderText
=
"Expiration Date"
UniqueName
=
"d_loc_expire"
DataFormatString
=
"{0:d}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"in_facility_loc"
AllowFiltering
=
"true"
HeaderText
=
"Facility LOC #"
UniqueName
=
"in_facility_loc"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_company"
AllowFiltering
=
"true"
HeaderText
=
"Company"
UniqueName
=
"n_company"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"t_added"
AllowFiltering
=
"true"
HeaderText
=
"Created Date"
UniqueName
=
"t_added"
DataFormatString
=
"{0:d}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ic_user_added"
AllowFiltering
=
"true"
HeaderText
=
"User Created"
UniqueName
=
"ic_user_added"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"v_comment"
DataFormatString
=
" {0}"
HeaderText
=
"Comments"
UniqueName
=
"v_comment"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"f_new_version"
DataType
=
"System.String"
UniqueName
=
"f_new_version"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridHyperLinkColumn
UniqueName
=
"LinkColumn"
DataTextField
=
"in_loc"
DataTextFormatString
=
"Edit"
Target
=
"_parent"
>
</
telerik:GridHyperLinkColumn
>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
<
br
/>
<
br
/>
<
strong
>LOC Detail</
strong
>
<
br
/>
Note: Unassigning contracts will automatically put the LOC back in "Input" status
<
telerik:RadGrid
ID
=
"RadGridDetail"
ShowStatusBar
=
"true"
runat
=
"server"
AllowSorting
=
"True"
AllowPaging
=
"True"
PageSize
=
"10"
DataSourceID
=
"SqlDataSource2"
GridLines
=
"None"
Skin
=
"Web20"
Width
=
"95%"
HorizontalAlign
=
"NotSet"
OnItemDataBound
=
"RadGridDetail_ItemDataBound"
OnDeleteCommand
=
"RadGridDetail_DeleteCommand"
OnUpdateCommand
=
"RadGridDetail_UpdateCommand"
>
<
MasterTableView
Width
=
"100%"
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ic_contract, y_underwriting"
DataSourceID
=
"SqlDataSource2"
ShowFooter
=
"True"
TableLayout
=
"Fixed"
EditMode
=
"PopUp"
>
<
EditFormSettings
InsertCaption
=
"Add new item"
CaptionFormatString
=
"Edit ProductID: {0}"
CaptionDataField
=
"in_loc"
>
<
FormTemplate
>
<
table
id
=
"Table1"
cellspacing
=
"1"
cellpadding
=
"1"
width
=
"250"
border
=
"0"
>
<
tr
>
<
td
>
</
td
>
<
td
>
</
td
>
</
tr
>
<
tr
>
<
td
>
FirstName:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox10"
Text='<%# Bind( "FirstName") %>' runat="server">
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
>
Last Name:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox11"
Text='<%# Bind( "LastName") %>' runat="server">
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
>
Title:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox12"
Text='<%# Bind( "Title") %>' runat="server">
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
hr
/>
</
td
>
</
tr
>
<
tr
>
<
td
>
Country:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
Text='<%# Bind( "Country" ) %>'>
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
>
City:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox5"
runat
=
"server"
Text='<%# Bind( "City") %>'>
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
>
Region:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TextBox6"
runat
=
"server"
Text='<%# Bind( "Region") %>'>
</
asp:TextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
>
Title Of Courtesy
</
td
>
<
td
>
</
td
>
</
tr
>
</
table
>
<
table
style
=
"width: 100%"
>
<
tr
>
<
td
align
=
"right"
colspan
=
"2"
>
<
asp:Button
ID
=
"Button1"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</
asp:Button
>
<
asp:Button
ID
=
"Button2"
Text
=
"Cancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
>
</
asp:Button
>
</
td
>
</
tr
>
</
table
>
</
FormTemplate
>
</
EditFormSettings
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ic_contract"
DataType
=
"System.String"
HeaderText
=
"Contract #"
SortExpression
=
"ic_contract"
UniqueName
=
"ic_contract"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"y_underwriting"
DataType
=
"System.Int32"
HeaderText
=
"Uw Year"
SortExpression
=
"y_underwriting"
UniqueName
=
"y_underwriting"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"d_effective"
DataType
=
"System.DateTime"
HeaderText
=
"Contract Eff Dt"
SortExpression
=
"d_effective"
UniqueName
=
"d_effective"
DataFormatString
=
"{0:d}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_user_title"
DataType
=
"System.String"
HeaderText
=
"Contract Title"
SortExpression
=
"n_user_title"
UniqueName
=
"n_user_title"
ColumnEditorID
=
"GridTextBoxColumnEditor1"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_cedant"
DataType
=
"System.String"
HeaderText
=
"Cedant"
SortExpression
=
"n_cedant"
UniqueName
=
"n_cedant"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_cedant_group"
DataType
=
"System.String"
HeaderText
=
"Cedant Group"
SortExpression
=
"n_cedant_group"
UniqueName
=
"n_cedant_group"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"n_cedant_parent"
DataType
=
"System.String"
HeaderText
=
"Cedant Parent"
SortExpression
=
"n_cedant_parent"
UniqueName
=
"n_cedant_parent"
FooterAggregateFormatString
=
"{0:N0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"a_loc_osr_booked"
DataType
=
"System.Double"
HeaderText
=
"Cedant OSR"
SortExpression
=
"a_loc_osr_booked"
UniqueName
=
"a_loc_osr_booked"
DataFormatString
=
"{0:N0}"
ItemStyle-HorizontalAlign
=
"Right"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:N0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"a_loc_ibnr_booked"
DataType
=
"System.Double"
HeaderText
=
"Cedant IBNR"
SortExpression
=
"a_loc_ibnr_booked"
UniqueName
=
"a_loc_ibnr_booked"
DataFormatString
=
"{0:N0}"
ItemStyle-HorizontalAlign
=
"Right"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:N0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"a_loc_upr_booked"
DataType
=
"System.Double"
HeaderText
=
"Cedant UPR"
SortExpression
=
"a_loc_upr_booked"
UniqueName
=
"a_loc_upr_booked"
DataFormatString
=
"{0:N0}"
ItemStyle-HorizontalAlign
=
"Right"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:N0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Update"
Text
=
"Update"
UniqueName
=
"UpdateColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Unassign this contract?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Unassign"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Unassign"
UniqueName
=
"UnassignColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
<
telerik:GridTextBoxColumnEditor
ID
=
"GridTextBoxColumnEditor1"
runat
=
"server"
TextBoxStyle-Width
=
"180px"
>
</
telerik:GridTextBoxColumnEditor
>
<
br
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
EnableViewState
=
"false"
></
asp:Label
>
<
br
/>
<
br
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="sp_gloc_header_sel_1 @c_company, @f_pasi, @in_loc, @y_loc">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"UserComp"
Type
=
"String"
SessionField
=
"UserComp"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"UserPasi"
Type
=
"String"
SessionField
=
"UserPasi"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"DumSessionParm1"
Type
=
"Int32"
SessionField
=
"DumSessionParm1"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"DumSessionParm2"
Type
=
"Int32"
SessionField
=
"DumSessionParm2"
></
asp:SessionParameter
>
</
SelectParameters
>
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="sp_gloc_detail_sel_2 @in_loc, @y_loc, @in_loc_version"
UpdateCommand="sp_gloc_detail_upd_1 @in_loc, @y_loc, @in_loc_version, @ic_contract, @y_underwriting, @a_loc_osr_booked, @a_loc_ibnr_booked, @a_loc_upr_booked, @ic_user">
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"in_loc"
PropertyName
=
"SelectedValues['in_loc']"
Type
=
"Int32"
/>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"y_loc"
PropertyName
=
"SelectedValues['y_loc']"
Type
=
"Int32"
/>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"in_loc_version"
PropertyName
=
"SelectedValues['in_loc_version']"
Type
=
"Int32"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"in_loc"
Type
=
"Int32"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"y_loc"
Type
=
"Int32"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"in_loc_version"
Type
=
"Int32"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"ic_contract"
Type
=
"String"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"y_underwriting"
Type
=
"Int32"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"a_loc_osr_booked"
Type
=
"Decimal"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"a_loc_ibnr_booked"
Type
=
"Decimal"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"a_loc_upr_booked"
Type
=
"Decimal"
></
asp:Parameter
>
<
asp:Parameter
Name
=
"ic_user"
Type
=
"String"
></
asp:Parameter
>
</
UpdateParameters
>
</
asp:SqlDataSource
>

The issue is in your ajax settings. You need to add 'RadGridLoc' in updated controls on the ajax call on the 'RadGridDetail' grid. Please make the following changes in ajax settings and see if it works.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridLOC"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridLOC"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridDetail"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridLOC"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
Thanks,
Princy.

I wasn't exactly sure if you wanted me to apply your latest suggestion of adding 'RadGridLoc' in updated controls on the ajax call on the 'RadGridDetail' grid alongside using the code you suggested previously. So I tried both ways. With the code you gave me, I still get the error:
"Unable to cast object of type 'System.Web.UI.WebControls.ContentPlaceHolder' to type 'Telerik.Web.UI.GridNestedViewItem'."
on this line of code:
GridNestedViewItem nestedItem = (GridNestedViewItem)grid.NamingContainer;
So I figured you wanted me to just add the master gird to the ajax call on detail grid without your suggested code. When I tried that, I did see that the master grid got updated after the delete, so I'm happy about that! On the other hand, now the detail grid disappears completely after the delete operation. And I know it happens because of the RadGridLOC.Rebind(). If I remove the rebind, the detail grid stays, but the master grid does not get updated. I'm guessing with a rebind, the master grid loses the row it was on, consequently, there is nothing to show in the detail grid??
Thanks.

Sorry for not making it clear. Yes, you don’t need to use the code that I suggested in the first forum. (I thought you were using hierarchical grid with NestedView Template and that’s why suggested that code)
Latest:-
I have tried your code at my end (Please not in my sample I was deleting a record from detail grid and updating corresponding row in master grid) and it was working fine when making the changes (with AjaxManager) that I suggested. And please note that in order to make the master grid updated you have to rebind that grid.
Regarding the Detail table disappearing issue, can you please elaborate what is happening in the Delete command? Is it deleting a record from master grid or Detail grid? What is the relation between the master grid and detail grid? Can you please provide some more information for further help?
I am sharing the code that I tried.
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
</
asp:ScriptManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridLOC"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridLOC"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridDetail"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridLOC"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridDetail"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadFilter
runat
=
"server"
ID
=
"RadFilterRGridLOC"
FilterContainerID
=
"RadGridLOC"
ShowApplyButton
=
"true"
ApplyButtonText
=
"Apply Filter"
Skin
=
"Web20"
/>
<
br
/>
<
asp:CheckBox
ID
=
"CheckBoxShowHistory"
runat
=
"server"
AutoPostBack
=
"true"
Text
=
"Show History"
/>
<
telerik:RadGrid
ID
=
"RadGridLOC"
runat
=
"server"
GridLines
=
"None"
AllowSorting
=
"True"
AllowFilteringByColumn
=
"true"
AllowPaging
=
"true"
AutoGenerateColumns
=
"False"
PageSize
=
"20"
Skin
=
"Web20"
DataSourceID
=
"SqlDataSource1"
Width
=
"95%"
OnItemDataBound
=
"RadGridLOC_ItemDataBound"
OnPreRender
=
"RadGridLOC_PreRender"
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
IsFilterItemExpanded
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
AllowFiltering
=
"true"
HeaderText
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CompanyName"
AllowFiltering
=
"true"
HeaderText
=
"CompanyName"
UniqueName
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContactName"
AllowFiltering
=
"true"
HeaderText
=
"ContactName"
UniqueName
=
"ContactName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
<
br
/>
<
br
/>
<
strong
>LOC Detail</
strong
>
<
br
/>
Note: Unassigning contracts will automatically put the LOC back in "Input" status
<
telerik:RadGrid
ID
=
"RadGridDetail"
ShowStatusBar
=
"true"
runat
=
"server"
AllowSorting
=
"True"
AllowPaging
=
"True"
PageSize
=
"10"
DataSourceID
=
"SqlDataSource2"
GridLines
=
"None"
Skin
=
"Web20"
Width
=
"95%"
HorizontalAlign
=
"NotSet"
OnItemDataBound
=
"RadGridDetail_ItemDataBound"
OnDeleteCommand
=
"RadGridDetail_DeleteCommand"
>
<
MasterTableView
Width
=
"100%"
AutoGenerateColumns
=
"False"
DataKeyNames
=
"OrderID"
DataSourceID
=
"SqlDataSource2"
ShowFooter
=
"True"
TableLayout
=
"Fixed"
EditMode
=
"PopUp"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
Display
=
"false"
UniqueName
=
"OrderID"
EditFormHeaderTextFormat
=
""
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
SortExpression
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Update"
Text
=
"Update"
UniqueName
=
"UpdateColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Unassign this contract?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Unassign"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Unassign"
UniqueName
=
"UnassignColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
<
telerik:GridTextBoxColumnEditor
ID
=
"GridTextBoxColumnEditor1"
runat
=
"server"
TextBoxStyle-Width
=
"180px"
>
</
telerik:GridTextBoxColumnEditor
>
<
br
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
EnableViewState
=
"false"
></
asp:Label
>
<
br
/>
<
br
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT top 5 * FROM Customers"
runat="server"></
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders " runat="server">
</
asp:SqlDataSource
>
</
form
>
C#:
protected
void
RadGridDetail_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
GridDataItem item = (GridDataItem)e.Item;
int
orderID = Convert.ToInt32(item.GetDataKeyValue(
"OrderID"
));
string
cusId = item[
"CustomerID"
].Text;
SqlConnection con =
new
SqlConnection(WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
SqlCommand cmd1 =
new
SqlCommand(
"delete from Orders where OrderID=@OrderID"
, con);
SqlCommand cmd2 =
new
SqlCommand(
"update Customers set ContactName=@ContactName where CustomerID=@CustomerID"
, con);
cmd1.Parameters.Add(
new
SqlParameter(
"@OrderID"
, orderID));
cmd2.Parameters.Add(
new
SqlParameter(
"@CustomerID"
, cusId));
cmd2.Parameters.Add(
new
SqlParameter(
"@ContactName"
,
"NEW"
));
try
{
con.Open();
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
RadGridLOC.Rebind();
}
finally
{
con.Close();
}
}
Thanks,
Princy.

I looked through your code and mine and it's pretty much the same. Maybe it's the way the grids are created???
Each row of the master grid is an LOC. Then when I click on a row in the master grid, the key is used to get the detail grid which contains one or multiple rows associated with that specific LOC. Just like your sample of Customer ID and Order ID.
"I have tried your code at my end (Please not in my sample I was deleting a record from detail grid and updating corresponding row in master grid) and it was working fine when making the changes (with AjaxManager) that I suggested. And please note that in order to make the master grid updated you have to rebind that grid."
I am deleting from the detail grid as well. Yes, I see that rebinding the master grid, updates it. So I am good with that.
Can you tell me what happens after a rebind? Does the master grid know which row it was on before the rebind (row click was on), that is when the delete happened? So that it can go back to being on that row?? I suspect without this information, the detail grid does not show.
Thanks again.
Some code that might help:
The datasource
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="sp_gloc_header_sel_1 @c_company, @f_pasi, @in_loc, @y_loc">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"UserComp"
Type
=
"String"
SessionField
=
"UserComp"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"UserPasi"
Type
=
"String"
SessionField
=
"UserPasi"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"DumSessionParm1"
Type
=
"Int32"
SessionField
=
"DumSessionParm1"
></
asp:SessionParameter
>
<
asp:SessionParameter
Name
=
"DumSessionParm2"
Type
=
"Int32"
SessionField
=
"DumSessionParm2"
></
asp:SessionParameter
>
</
SelectParameters
>
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="sp_gloc_detail_sel_2 @in_loc, @y_loc, @in_loc_version">
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"in_loc"
PropertyName
=
"SelectedValues['in_loc']"
Type
=
"Int32"
/>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"y_loc"
PropertyName
=
"SelectedValues['y_loc']"
Type
=
"Int32"
/>
<
asp:ControlParameter
ControlID
=
"RadGridLOC"
Name
=
"in_loc_version"
PropertyName
=
"SelectedValues['in_loc_version']"
Type
=
"Int32"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
I use ItemDataBound methods as below for both grids.
double totalOsr;
double totalIbnr;
double totalUpr;
protected void RadGridLOC_ItemDataBound(object sender, GridItemEventArgs e)
{
RadGridLOC.GroupingSettings.CaseSensitive = false; // to make filtering case-insensitive
if (e.Item is GridPagerItem)
{
GridPagerItem pager = (GridPagerItem)e.Item;
RadComboBox PageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox");
PageSizeComboBox.Visible = false;
}
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
int rowIdx = item.ItemIndex;
string dtEff = item["d_loc_effective"].Text.ToString();
string dtExp = item["d_loc_expire"].Text.ToString();
if (dtEff == "1/1/1901")
{
item["d_loc_effective"].Text = " ";
}
if (dtExp == "1/1/1901")
{
item["d_loc_expire"].Text = " ";
}
string strVal = item["in_facility_loc"].Text.ToString();
if ((strVal == "0") || (strVal == null))
{
item["in_facility_loc"].Text = " ";
}
string val1 = item["in_loc"].Text;
string val2 = item["y_loc"].Text;
HyperLink hLink = (HyperLink)item["LinkColumn"].Controls[0];
hLink.NavigateUrl = "~/CreateLOC.aspx?in_loc=" + val1 + "&y_loc=" + val2 + "&type=edit";
if (Convert.ToInt32(Session["AuthMode"].ToString()) == 1)
{
hLink.Enabled = false;
hLink.ForeColor = ColorTranslator.FromHtml("#83ABD8");
}
if (item["c_loc_status"].Text == "04")
{
//If loc status is Issued
hLink.Text = "Amend";
hLink.ToolTip = "Amend";
if (item["f_new_version"].Text == "Y")
{
hLink.Enabled = false;
hLink.ForeColor = ColorTranslator.FromHtml("#83ABD8");
hLink.ToolTip = "Cannot amend. There is already a new version of this LOC.";
}
}
// If status is Expired or Superseded, then no edit allowed
if (item["c_loc_status"].Text == "05" || item["c_loc_status"].Text == "06")
{
//If loc status is Issued
hLink.Enabled = false;
hLink.ForeColor = ColorTranslator.FromHtml("#83ABD8");
foreach (GridColumn column in RadGridLOC.MasterTableView.RenderColumns)
{
if (column is GridBoundColumn)
{
//This will change color of the row to grey to show inactive versions of LOC.
item[column.UniqueName].ForeColor = ColorTranslator.FromHtml("#808080");
}
}
}
if (item["v_comment"].Text.Length > 20)
{
item["v_comment"].ToolTip = item["v_comment"].Text.ToString();
item["v_comment"].Text = item["v_comment"].Text.Substring(0, 21) + "...";
}
}
}
protected void RadGridDetail_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
double totOsr = Double.Parse(item["a_loc_osr_booked"].Text.ToString());
totalOsr += totOsr;
double totIbnr = Double.Parse(item["a_loc_ibnr_booked"].Text.ToString());
totalIbnr += totIbnr;
double totUpr = Double.Parse(item["a_loc_upr_booked"].Text.ToString());
totalUpr += totUpr;
ImageButton gridbtn = (ImageButton)item["UnassignColumn"].Controls[0];
LinkButton lnkEdit = (LinkButton)item["EditColumn"].Controls[0];
if (RadGridLOC.SelectedItems.Count > 0)
{
string locsts = RadGridLOC.SelectedValues["c_loc_status"].ToString();
if (locsts == "04" || locsts == "05" || locsts == "06" || (Convert.ToInt32(Session["AuthMode"].ToString()) == 1))
{
// If LOC status is Issued, Expired or Superseded, or authority is browse only, no Edit allowed
gridbtn.Enabled = false;
gridbtn.ForeColor = ColorTranslator.FromHtml("#83ABD8");
gridbtn.ToolTip = "Cannot unassign.";
lnkEdit.Enabled = false;
lnkEdit.ForeColor = ColorTranslator.FromHtml("#83ABD8");
lnkEdit.ToolTip = "Cannot edit.";
}
}
}
if (e.Item is GridFooterItem)
{
GridFooterItem footerItem = e.Item as GridFooterItem;
footerItem["a_loc_osr_booked"].Text = String.Format("{0:###,##0.00}", totalOsr);
footerItem["a_loc_osr_booked"].HorizontalAlign = HorizontalAlign.Right;
footerItem["a_loc_ibnr_booked"].Text = String.Format("{0:###,##0.00}", totalIbnr);
footerItem["a_loc_ibnr_booked"].HorizontalAlign = HorizontalAlign.Right;
footerItem["a_loc_upr_booked"].Text = String.Format("{0:###,##0.00}", totalUpr);
footerItem["a_loc_upr_booked"].HorizontalAlign = HorizontalAlign.Right;
footerItem["n_cedant_parent"].Text = "Total: " + String.Format("{0:###,##0.00}", totalOsr + totalIbnr + totalUpr);
footerItem["n_cedant_parent"].HorizontalAlign = HorizontalAlign.Right;
}
}

Yes, I understood your issue. Since we are rebinding the parent grid, the selected item will not persist. So can you try the following approach to solve this. You can save the parent grid item index in DeleteCommand and in parent grid's PreRender event select the item again with the saved index and rebind the detail grid like below.
C#:
static
int
parentRowIndex = -1;
protected
void
RadGridLOC_PreRender(
object
sender, EventArgs e)
{
if
(parentRowIndex > -1)
{
GridDataItem item = (GridDataItem)RadGridLOC.Items[parentRowIndex];
item.Selected =
true
;
RadGridDetail.Rebind();
}
}
protected
void
RadGridDetail_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
parentRowIndex =Convert.ToInt32(RadGridLOC.SelectedIndexes[0]);
//getting parent row index
GridDataItem item = (GridDataItem)e.Item;
int
orderID = Convert.ToInt32(item.GetDataKeyValue(
"OrderID"
));
string
cusId = item[
"CustomerID"
].Text;
SqlConnection con =
new
SqlConnection(WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
SqlCommand cmd1 =
new
SqlCommand(
"delete from Orders where OrderID=@OrderID"
, con);
SqlCommand cmd2 =
new
SqlCommand(
"update Customers set ContactName=@ContactName where CustomerID=@CustomerID"
, con);
cmd1.Parameters.Add(
new
SqlParameter(
"@OrderID"
, orderID));
cmd2.Parameters.Add(
new
SqlParameter(
"@CustomerID"
, cusId));
cmd2.Parameters.Add(
new
SqlParameter(
"@ContactName"
,
"NEW"
));
try
{
con.Open();
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
RadGridLOC.Rebind();
}
finally
{
con.Close();
}
}
Thanks,
Princy.
