Have used imagebutton as buttotype for edid and delete but it is giving error:
Sys.WebForms.PageRequestManagerServerErrorException: Unable to cast object of type 'Telerik.Web.UI.GridLinkButton' to type 'System.Web.UI.WebControls.ImageButton'.
6 Answers, 1 is accepted

Can you please provide your line of codes from where this error raised?
Note : You get this error because there is miss match in Casting. So Replace ImageButton to LinkButton.
Thanks,
Jayesh Goyani

Here is the sample demo for CRUD operation in hierarchy.
For the second question, such errors when there is a mismatch in the type casting. Since you are using ImageButton, you need to access it as shown below.
C#:
ImageButton imgbtn = (ImageButton)item[
"UniqueName"
].Controls[0];
Thanks,
Shinu.

protected void rgdLabTest_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "Detail")
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
ImageButton updateBtn = (ImageButton)editItem.FindControl("UpdateButton");
ImageButton cancelBtn = (ImageButton)editItem.FindControl("CancelButton");
if (updateBtn != null)
{
updateBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_025", BOL.Classes.EHRSessions.Culture);
updateBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
updateBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
updateBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/apply_ico.png");
cancelBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_006", BOL.Classes.EHRSessions.Culture);
cancelBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
cancelBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
cancelBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/close_pop_ico.png");
//updateBtn.Attributes.Add("OnClick", "return ValidateGroup('" + t1.ClientID + "','" + t2.ClientID + "');");
}
ImageButton insertBtn = (ImageButton)editItem.FindControl("PerformInsertButton");
if (insertBtn != null)
{
insertBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_005", BOL.Classes.EHRSessions.Culture);
insertBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
insertBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
insertBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/apply_ico.png");
cancelBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_006", BOL.Classes.EHRSessions.Culture);
cancelBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
cancelBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
cancelBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/close_pop_ico.png");
// insertBtn.Attributes.Add("OnClick", "return ValidateGroup('" + t1.ClientID + "','" + t2.ClientID + "');");
}
}
}
else
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
TextBox t1 = (TextBox)editItem["AttributeName"].Controls[0];
ImageButton updateBtn = (ImageButton)editItem.FindControl("UpdateButton");
ImageButton cancelBtn = (ImageButton)editItem.FindControl("CancelButton");
if (updateBtn != null)
{
updateBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_025", BOL.Classes.EHRSessions.Culture);
updateBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
updateBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
updateBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/apply_ico.png");
cancelBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_006", BOL.Classes.EHRSessions.Culture);
cancelBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
cancelBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
cancelBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/close_pop_ico.png");
//updateBtn.Attributes.Add("OnClick", "return ValidateGroup('" + t1.ClientID + "','" + t2.ClientID + "');");
}
ImageButton insertBtn = (ImageButton)editItem.FindControl("PerformInsertButton");
if (insertBtn != null)
{
insertBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_005", BOL.Classes.EHRSessions.Culture);
insertBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
insertBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
insertBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/apply_ico.png");
cancelBtn.ToolTip = Utility.ContentFetcher.GetResourceContent("RES_006", BOL.Classes.EHRSessions.Culture);
cancelBtn.Attributes.Add("onmouseover", "visibilityOfToolTip(this, 1);");
cancelBtn.Attributes.Add("onmouseout", "visibilityOfToolTip(this);");
cancelBtn.ImageUrl = ResolveUrl("~/App_Themes/Bari_Default/images/close_pop_ico.png");
// insertBtn.Attributes.Add("OnClick", "return ValidateGroup('" + t1.ClientID + "','" + t2.ClientID + "');");
}
}
if (e.Item is GridPagerItem && !(e.Item as GridPagerItem).IsTopPager)
{
rgdLabTest.PagerStyle.AlwaysVisible = (rgdLabTest.MasterTableView != null && rgdLabTest.MasterTableView.DataSourceCount > 5);
}
}
}
And Below id the Grid:
<telerik:RadGrid ID="rgdLabTest" runat="server" GridLines="None" AllowAutomaticDeletes="false"
AllowAutomaticInserts="false" PageSize="5" AllowAutomaticUpdates="false" AllowPaging="True"
AutoGenerateColumns="False" OnDetailTableDataBind="rgdLabTest_DetailTableDataBind"
Skin="BariRC" EnableEmbeddedSkins="false" OnInsertCommand="rgdLabTest_InsertCommand"
OnItemCommand="rgdLabTest_ItemCommand" OnItemDataBound="rgdLabTest_ItemDataBound"
OnNeedDataSource="rgdLabTest_NeedDataSource" OnUpdateCommand="rgdLabTest_UpdateCommand">
<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView Width="100%" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage"
DataKeyNames="Id" HorizontalAlign="NotSet" EditMode="EditForms" AutoGenerateColumns="False"
CommandItemSettings-ShowRefreshButton="false" CommandItemSettings-AddNewRecordImageUrl="../../App_Themes/Bari_Default/images/add_ico.png">
<Columns>
<telerik:GridBoundColumn DataField="AttributeName" HeaderText="AttributeName" SortExpression="AttributeName"
UniqueName="AttributeName" ColumnEditorID=" GridTextBoxColumnEditor1" MaxLength="200">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
HeaderText="Edit" EditImageUrl="~/App_Themes/Bari_Default/images/edit_ico.png"
ItemStyle-Width="200px" ItemStyle-Wrap="false">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="" ConfirmDialogType="RadWindow" ConfirmTitle="Delete"
ButtonType="ImageButton" UniqueName="DeleteColumn" HeaderText="Delete" ImageUrl="~/App_Themes/Bari_Default/images/delete_ico.png">
</telerik:GridButtonColumn>
</Columns>
<DetailTables>
<telerik:GridTableView Name="Detail" Width="100%" runat="server" CommandItemDisplay="Top"
DataKeyNames="Id,GenderLookupDisplayValue" CommandItemSettings-ShowRefreshButton="false">
<Columns>
<telerik:GridTemplateColumn HeaderText="Gender" UniqueName="GenderLookupDisplayValue">
<EditItemTemplate>
<telerik:RadComboBox ID="rcbGenderLookupDisplayValue" runat="server" AutoPostBack="false"
DataValueField="GenderLookupDisplayValue" DataTextField="GenderLookupDisplayValue"
Skin="BariRC" EnableEmbeddedSkins="false">
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGenderLookupDisplayValue" runat="server" Text='<%#Eval("GenderLookupDisplayValue")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridNumericColumn DataField="StartAge" HeaderText="Start Age" SortExpression="StartAge"
UniqueName="StartAge" ColumnEditorID="GridNumericColumnEditor1" MaxLength="6">
</telerik:GridNumericColumn>
<telerik:GridNumericColumn DataField="EndAge" HeaderText="End Age" SortExpression="EndAge"
UniqueName="EndAge" ColumnEditorID="GridNumericColumnEditor2" MaxLength="6">
</telerik:GridNumericColumn>
<telerik:GridBoundColumn DataField="NormalStartRange" HeaderText="Normal StartRange"
SortExpression="NormalStartRange" UniqueName="NormalStartRange" ColumnEditorID="GridTextBoxColumnEditor2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="NormalEndRange" HeaderText="Normal EndRange"
SortExpression="NormalEndRange" UniqueName="NormalEndRange" ColumnEditorID="GridTextBoxColumnEditor3">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Unit" HeaderText="Unit" SortExpression="Unit"
UniqueName="" ColumnEditorID="GridTextBoxColumnEditor4">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
HeaderText="Edit" EditImageUrl="~/App_Themes/Bari_Default/images/edit_ico.png"
ItemStyle-Width="200px" ItemStyle-Wrap="false">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="" ConfirmDialogType="RadWindow" ConfirmTitle="Delete"
ButtonType="ImageButton" UniqueName="DeleteColumn" HeaderText="Delete" ImageUrl="~/App_Themes/Bari_Default/images/delete_ico.png">
</telerik:GridButtonColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>

Since you are using the EditMode as EditForms, access it using GridEditFormItem.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name ==
"Detail"
)
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
LinkButton updateBtn = (LinkButton)editItem.FindControl(
"UpdateButton"
);
}
}
Thanks,
Shinu.

In the code behind as well as designer i have used iamgebutton still the error is coming.

Please check below code snippet.
Note : Please check "
EditFormSettings
" in below code snippet.<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
AutoGenerateColumns
=
"false"
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn"
ButtonType
=
"ImageButton"
CancelImageUrl
=
"~/RadControls/Grid/Skins/Default/Cancel.gif"
UpdateImageUrl
=
"~/RadControls/Grid/Skins/Default/Update.gif"
InsertImageUrl
=
"~/RadControls/Grid/Skins/Default/Insert.gif"
>
</
EditColumn
>
</
EditFormSettings
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"ContactName"
HeaderText
=
"Contact name"
DataField
=
"ContactName"
/>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
ButtonType
=
"ImageButton"
EditImageUrl
=
"~/RadControls/Grid/Skins/Default/Edit.gif"
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
ButtonType
=
"ImageButton"
ImageUrl
=
"~/RadControls/Grid/Skins/Default/Delete.gif"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Thanks,
Jayesh Goyani