Hi, I am trying to follow your example in the Telerik help pages (http://www.telerik.com/help/aspnet-ajax/grid-inserting-values-inplace-and-editforms.html) to implement inserting a new row into a RadGrid. I am using a button to fire InitInsert which successfully creates an empty row that the user can input information, but when I fire the InsertCommand by clicking another button, in the InsertCommand event handler, GridCommandEventArgs.Item evaluates to null. Any suggestions?
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="grdTradesFile"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="grdTradesFile" LoadingPanelID="RadAjaxLoadingPanel1"/> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="50" /> <telerik:RadGrid ID="grdTradesFile" runat="server" Skin="Web20" Width="97%" AllowMultiRowSelection="True" AllowMultiRowEdit="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AutoGenerateColumns="False" ShowStatusBar="true" OnNeedDataSource="grdTradesFile_NeedDataSource" SelectedItemStyle-BorderColor="Moccasin" SelectedItemStyle-BackColor="Moccasin" onitemcommand="grdTradesFile_ItemCommand" oncancelcommand="grdTradesFile_CancelCommand" oneditcommand="grdTradesFile_EditCommand" onupdatecommand="grdTradesFile_UpdateCommand" oninsertcommand="grdTradesFile_InsertCommand"> <ClientSettings> <Selecting AllowRowSelect="true" /> </ClientSettings> <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" AllowAutomaticDeletes="false" AllowAutomaticInserts="true" AllowAutomaticUpdates="false" AutoGenerateColumns="false" Width="100%" DataKeyNames="Trade" ClientDataKeyNames="Trade"> <CommandItemTemplate> <asp:Button ID="Button1" runat="server" CommandName="EditSelected" Text="Edit Selected" Width="120" Visible='<%# grdTradesFile.EditIndexes.Count == 0 %>'></asp:Button> <asp:Button ID="Button2" runat="server" CommandName="CancelAll" Text="Cancel All" Width="120" Visible='<%# grdTradesFile.EditIndexes.Count != 0 %>'></asp:Button> <asp:Button ID="Button3" runat="server" CommandName="UpdateEdited" Text="Update Edited" Width="120" Visible='<%# grdTradesFile.EditIndexes.Count > 0 %>'></asp:Button> <asp:Button ID="Button4" runat="server" CommandName="DeleteSelected" Text="Delete Selected" Width="120" Visible='<%# grdTradesFile.EditIndexes.Count == 0 %>'></asp:Button> <asp:Button ID="Button5" runat="server" CommandName="InitInsert" Text="New Trade" Width="120" Visible='<%# !grdTradesFile.MasterTableView.IsItemInserted && grdTradesFile.EditIndexes.Count == 0 %>'></asp:Button> <asp:Button ID="Button6" runat="server" CommandName="PerformInsert" Text="Add Trade" Width="120" Visible='<%# grdTradesFile.MasterTableView.IsItemInserted %>'></asp:Button> </CommandItemTemplate> <Columns> <telerik:GridClientSelectColumn /> <telerik:GridBoundColumn DataField="Trade" HeaderText="TRADE" UniqueName="Trade" /> <telerik:GridBoundColumn DataField="Coupon" HeaderText="COUPON" UniqueName="Coupon" /> <telerik:GridBoundColumn DataField="Price" HeaderText="PRICE" UniqueName="Price" /> <telerik:GridBoundColumn DataField="Cross" HeaderText="PREMIUM CROSS" UniqueName="PremiumCross" /> <telerik:GridBoundColumn DataField="Comments" HeaderText="COMMENTS" UniqueName="Comments" /> </Columns> </MasterTableView> </telerik:RadGrid>protected void grdTradesFile_InsertCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; DataRow newRow = tradesTable.NewRow(); DataRow[] allValues = tradesTable.Select("", PRIMARY_KEY_COLUMN_NAME, DataViewRowState.CurrentRows); if (allValues.Length > 0) { newRow[PRIMARY_KEY_COLUMN_NAME] = (int)allValues[allValues.Length - 1][PRIMARY_KEY_COLUMN_NAME] + 1; } else { newRow[PRIMARY_KEY_COLUMN_NAME] = 1; //the table is empty; } //Set new values Hashtable newValues = new Hashtable(); //The GridTableView will fill the values from all editable columns in the hash e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); try { foreach (DictionaryEntry entry in newValues) { newRow[(string)entry.Key] = entry.Value; } } catch (Exception ex) { } tradesTable.Rows.Add(newRow); grdTradesFile.Rebind(); saveChanges(); }