Hi,
I am getting the following error when I am performing insert using "PerformInsert" from CommandItemTemplate.
Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridEditFormInsertItem'
ASPX Page : Grid Definition
ASPX : Command Item Template Definition
C# : Insert functionality inplemented in Item Command Event
I am getting error in line 6:
"GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;"
I have implemented Update and Delete methods similarly from Command Item Template, they seem to work fine. Just Insert is giving me this particular error.
But if i use the "Insert" button that comes by default in edit form, it is working fine.
I hope this information is sufficient. I you need further information please do let me know.
P.S : I have seen a few other suggestions in the forum saying to remove
AllowAutomaticUpdates="true", AllowAutomaticInserts="true". I have removed all of them.
I am getting the following error when I am performing insert using "PerformInsert" from CommandItemTemplate.
Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridEditFormInsertItem'
ASPX Page : Grid Definition
<telerik:RadGrid ID="RadGrid1" Skin="Sunset" GridLines="None" runat="server" | |
Width="97%" AllowPaging="True" AutoGenerateColumns="False" AllowMultiRowEdit="True" | |
OnNeedDataSource="RadGrid1_NeedDataSource" | |
AllowFilteringByColumn="True" | |
AllowSorting="True" PageSize="5" AllowMultiRowSelection="True" | |
ongridexporting="RadGrid1_GridExporting" OnItemCreated="RadGrid1_ItemCreated" | |
OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound"> | |
<HeaderContextMenu Skin="Inox" EnableTheming="True"> | |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> | |
</HeaderContextMenu> | |
<PagerStyle Mode="NextPrevNumericAndAdvanced" /> | |
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="DespatchNum" GridLines="None" | |
AutoGenerateColumns="False" EditMode="EditForms"> | |
<Columns> |
<CommandItemTemplate> | |
<div style="padding: 0 5px;"> | |
Custom command item template | |
<asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Edit.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Update.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>' CausesValidation="False"> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Cancel.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnAddNew" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/AddRecord.gif" /></asp:LinkButton> | |
<%--<asp:LinkButton ID="btnInsert" runat="server" CommandName="PerformInsert" Text="Insert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Update.gif" /></asp:LinkButton> --%> | |
<asp:LinkButton ID="btnInsert" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Update.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnDelete" OnClientClick="javascript:return confirm('Delete all selected customers?')" runat="server" CommandName="DeleteAll"> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Delete.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnRefresh" runat="server" CommandName="RebindGrid"> | |
<img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Sunset/Refresh.gif" /></asp:LinkButton> | |
<asp:LinkButton ID="btnExportExcel" runat="server" CommandName="ExportToExcel"> | |
<img style="border:0px;vertical-align:middle;" alt="Export To Excel" src="" /></asp:LinkButton> | |
</div> | |
</CommandItemTemplate> |
C# : Insert functionality inplemented in Item Command Event
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) | |
{ | |
if (e.CommandName == "PerformInsert") | |
{ | |
//GridDataInsertItem insertedItem = e.Item as GridDataInsertItem; | |
GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; | |
//GridDataInsertItem insertedItem = (GridDataInsertItem)e.Item; | |
string Status = (insertedItem["DespatchStatus"].Controls[0] as TextBox).Text; | |
string RegionCode = (insertedItem["RegionCode"].FindControl("txtRegionCode") as TextBox).Text; | |
string LabCode = (insertedItem["LabCode"].Controls[0] as TextBox).Text; | |
string SampleCode = (insertedItem["SampleCode"].Controls[0] as RadComboBox).SelectedValue.ToString(); | |
} | |
} |
I am getting error in line 6:
"GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;"
I have implemented Update and Delete methods similarly from Command Item Template, they seem to work fine. Just Insert is giving me this particular error.
But if i use the "Insert" button that comes by default in edit form, it is working fine.
I hope this information is sufficient. I you need further information please do let me know.
P.S : I have seen a few other suggestions in the forum saying to remove
AllowAutomaticUpdates="true", AllowAutomaticInserts="true". I have removed all of them.