This is a migrated thread and some comments may be shown as answers.
RadGrid Delete row doesn't work
5 Answers 143 Views
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 16 Dec 2010, 08:07 AM
Hi,

I need your help to the following problem I am facing. I have a RadGrid loaded with data. Inserting and editing rows in RadGrid works fine. Deletion of a row doesn't work. Every time I try to delete a row I am getting the following error:
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.GridTemplateColumn.FillValues(IDictionary newValues, GridEditableItem editableItem) +435
   Telerik.Web.UI.GridEditableItem.ExtractValues(IDictionary newValues) +164
   Telerik.Web.UI.GridTableView.ExtractValuesFromItem(IDictionary newValues, GridEditableItem editedItem) +116
   Telerik.Web.UI.GridTableView.PerformDelete(GridEditableItem editedItem, Boolean suppressRebind) +174
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +4861
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +137
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +111
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
My RadGrid code is listed below :
<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True"
            AllowPaging="True" DataSourceID="UserDS" AllowSorting="True"
            AllowFilteringByColumn="True" AllowMultiRowEdit="True"
            Skin="Telerik" AutoGenerateColumns="False" ShowGroupPanel="True">
            <PagerStyle Mode="NextPrevAndNumeric" />
<HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
 
               <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="Id"
                DataSourceID="UserDS" HorizontalAlign="NotSet" EditMode="InPlace">
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        <ItemStyle CssClass="MyImageButton" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                        UniqueName="Name" ColumnEditorID="GridTextBoxColumnName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" SortExpression="Surname"
                        UniqueName="Surname" ColumnEditorID="GridTextBoxColumnSurname">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="User_Name" HeaderText="Username" SortExpression="User_Name"
                        UniqueName="User_Name" ColumnEditorID="GridTextBoxColumnUserName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Id_Number" HeaderText="Id Number" SortExpression="Id_Number"
                        UniqueName="Id_Number" ColumnEditorID="GridTextBoxColumnIdNumber"
                        DataType="System.Int32">
                    </telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataField="Role_Id" DataSourceID="RoleDdDS"
                        HeaderText="Role" ListTextField="Role" ListValueField="Id"
                        UniqueName="Role_Id" ColumnEditorID="GridDropDownColumnEditor1">
                    </telerik:GridDropDownColumn>
                    <telerik:GridTemplateColumn UniqueName="Password" AllowFiltering="false">
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="RadTextBox1" Runat="server" TextMode="Password">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidatorPassword" runat="server"
                                ControlToValidate="RadTextBox1" Display="Static" Text="*"
                                SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <HeaderTemplate>
                            <asp:Label ID="Label1" runat="server" Text="Password"></asp:Label>
                        </HeaderTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn ConfirmText="Delete this user" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                        UniqueName="DeleteColumn">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>
                     
                </Columns>
                <EditFormSettings ColumnNumber="2" CaptionDataField="User" CaptionFormatString="Edit properties of User {0}" InsertCaption="New User">
                   <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="Insert User" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
            </MasterTableView>
            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
                        AllowDragToGroup="True">
                <ClientEvents OnRowDblClick="RowDblClick" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
        </telerik:RadGrid>
        </asp:Panel>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
            <Windows>
                <telerik:RadWindow ID="RadWindow" runat="server" style="display:none;">
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
        <br />
        <asp:SqlDataSource ID="UserDS" runat="server"
            ConnectionString="<%$ ConnectionStrings:sample_ConnectionString %>"
            ProviderName="System.Data.SqlClient"
            DeleteCommand="UPDATE [User] SET [Is_Deleted]=1 WHERE [Id]=@original_Id"
            InsertCommand="INSERT INTO [User] (User_Name, Name, Surname, Id_Number, Role_Id, Password) VALUES (@User_Name,@Name,@Surname,@Id_Number,@Role_Id,@Password)"
            SelectCommand="SELECT * FROM [User]"
            UpdateCommand="UPDATE [User] SET [User_Name] = @User_Name, [Name] = @Name, [Surname] = @Surname, [Id_Number] = @Id_Number, [Role_Id] = @Role_Id, [Password]=@Password WHERE [Id]=@original_Id"
            ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}">
        <DeleteParameters>
                <asp:Parameter Name="original_Id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="User_Name" Type="String" />
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Surname" Type="String" />           
            <asp:Parameter Name="Id_Number" Type="Int32" />
            <asp:Parameter Name="Role_Id" Type="Int32" />
            <asp:Parameter Name="Password" Type="String" />
            <asp:Parameter Name="original_Id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="User_Name" Type="String" />
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Surname" Type="String" />           
            <asp:Parameter Name="Id_Number" Type="Int32" />
            <asp:Parameter Name="Role_Id" Type="Int32" />
            <asp:Parameter Name="Password" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="RoleDdDS" runat="server"
            ConnectionString="<%$ ConnectionStrings:sample_ConnectionString %>"
            SelectCommand="SELECT Id, Role FROM Role"></asp:SqlDataSource>

I have log the SQL Server to see if the Delete statement executes but it's not. By pressing the delete I get immediately the error page.
Other Information:

  Microsoft Visual Studio 2008 Version 9.0.30729.1SP
  Microsoft .NET Framework Version 3.5 SP1
  Telerik Version v.2010.3.1215.35
  Operating System: Windows 7
  Browser : Firefox
  Programming Language : VB.NET


Can anybody help me with my error?

Thanks
Pan

5 Answers, 1 is accepted

Sort by
0
George
Top achievements
Rank 1
answered on 16 Dec 2010, 11:45 AM
Problem solved... Ignore this post please
0
Arno
Top achievements
Rank 2
answered on 28 Dec 2010, 02:42 PM
Hi Pan,

How did you solve this? I'm looking at the same problem.
0
Arno
Top achievements
Rank 2
answered on 28 Dec 2010, 03:06 PM
I found another post that solved this. For other people running into this:

This was a part of my code in a RadGrid:

<telerik:GridTemplateColumn HeaderText="A header"
                        UniqueName="NumberSellers" HeaderStyle-Width="5em">
  <EditItemTemplate>
     -
  </EditItemTemplate>
</telerik:GridTemplateColumn>

The work around is to add an empty ItemTemplate. So, like this:

<telerik:GridTemplateColumn HeaderText="A header"
                        UniqueName="NumberSellers" HeaderStyle-Width="5em">
  <ItemTemplate />
  <EditItemTemplate>
     -
  </EditItemTemplate>
</telerik:GridTemplateColumn>
0
Jako
Top achievements
Rank 1
answered on 21 Feb 2013, 12:50 PM
Thanks Arno

This worked for me as well

Well spotted!
0
Mark
Top achievements
Rank 1
answered on 12 Jun 2013, 12:16 AM
Thank you for posting this. So simple, but I've spent way too much time trying to figure this out.
Tags
Grid
Asked by
George
Top achievements
Rank 1
Answers by
George
Top achievements
Rank 1
Arno
Top achievements
Rank 2
Jako
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Share this question
or