This is a migrated thread and some comments may be shown as answers.

RadGrid Update Command Not Working-Please help!

8 Answers 646 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike McCoy
Top achievements
Rank 1
Mike McCoy asked on 09 Jun 2010, 08:47 PM
Hello All,

I have been through and through many examples and postings and, for the life of me, do not understand what I am doing wrong. 

I am trying to get the values out of the update template to use in an update statement in the code behind. When I set the var values, it is setting the original text box value and not the edited value. 

For example the original value is "Lake Erie Spring Bass Tournament". If I edit and change this value, my var t is set to the original value. 

Any info is greatly appreciated.

Thank you,
Mike

Here is my code:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True"  
    AutoGenerateColumns="False" GridLines="None" AutoGenerateEditColumn="True" > 
<HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu> 
 
<MasterTableView DataKeyNames="ID" > 
    <Columns> 
         <telerik:GridBoundColumn DataField="ID" HeaderText="ID"  
            UniqueName="column51" SortExpression="ID" Visible="false"  
             DataType="System.Int32" ReadOnly="True" > 
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Tournament" HeaderText="Tournament"  
            UniqueName="Tournament" SortExpression="Tournament"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Date" HeaderText="Date"  
            UniqueName="Date" SortExpression="Date"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Boats" HeaderText="Boats"  
            UniqueName="Boats" SortExpression="Boats"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Finished" HeaderText="Finished"  
            UniqueName="Finished" SortExpression="Finished"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Fee" HeaderText="Fee" UniqueName="Fee"  
            SortExpression="Fee"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Winnings" HeaderText="Winnings"  
            UniqueName="Winnings" SortExpression="Winnings"
        </telerik:GridBoundColumn> 
    </Columns> 
 
</MasterTableView> 
</telerik:RadGrid> 



    Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand 
 
        Dim edititem As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
        Dim id As String = edititem.GetDataKeyValue("ID").ToString() 
        Dim t As String = (TryCast(edititem("Tournament").Controls(0), TextBox)).Text 
 
 
        ' dbinteractions.UpdateTournTrackerRecordByID(id, t) 
 
    End Sub

8 Answers, 1 is accepted

Sort by
0
Mike McCoy
Top achievements
Rank 1
answered on 10 Jun 2010, 02:34 PM
Nobody can tell me what I am doing wrong there or at least point me in the right direction?
0
Rosen
Telerik team
answered on 11 Jun 2010, 07:15 AM
Hello Mike,

You should ensure that you are not databinding the grid control on every postback (returning it to its original state).
Also, as from the snippets you have pasted is not clear how the control gets populated, you may take a look at the following articles on suggested way to populate RadGrid when using CRUD operations and make sure you are using one of them:

    - Advanced Data-binding (using NeedDataSource event)
    - Declarative DataSource

All the best,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Siraj
Top achievements
Rank 1
answered on 06 Feb 2012, 05:07 PM
Hi

Replying to a quite a old post as could not see it has been resolved.

This did not work for me correctly and very similar to Mike's situation. I think what Mike has done is correct but he need to add Template Columns to the fields those required updating programmatically at UpdateCommand event. Edit Controls those are bound to these fields should be replaced with Eval instead of Bind statement.

<EditItemTemplate>
    <telerik:RadTextBox ID="txtEdtEditedOn" Runat="server"
        Text='<%# Eval("EditedOn") %>' Enabled="false">
    </telerik:RadTextBox>
</EditItemTemplate>

Regards,
Sirajz
0
Tan
Top achievements
Rank 1
answered on 19 Mar 2012, 04:21 AM
Hi Rosen,
First, I must say thank you very much about suggests "You should ensure that you are not databinding the grid control on every postback (returning it to its original state)." . I lucky when I search google and find out this post.
thanks you again.
^^
0
Mike
Top achievements
Rank 1
answered on 08 Mar 2014, 05:22 PM
i have the same problem, my RadGrid is not updating nor is it inserting but the delete works.
please help, i have turned the auto update/insert/delete to True but still doesnt do anything as if the button wasn't linked to any code.

here is my radgrid:

 <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
        AllowAutomaticDeletes="True" AllowSorting="True" CellSpacing="0" GridLines="None"
        Skin="Metro" Width="100%" AllowFilteringByColumn="false">
       
        <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="ID" CommandItemDisplay="Top">
           
            <Columns>
            
                <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"
                    FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" Visible="true"
                    SortExpression="ID" UniqueName="ID">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="Marque"
                    FilterControlAltText="Filter Marque column" HeaderText="Marque"
                    SortExpression="Marque" UniqueName="Marque">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="Model"
                    FilterControlAltText="Filter Model column" HeaderText="Model"
                    SortExpression="Model" UniqueName="Model">
                </telerik:GridBoundColumn>
                
                <telerik:GridDateTimeColumn DataField="DateProd" DataType="System.DateTime"
                    FilterControlAltText="Filter DateProd column" HeaderText="DateProd"
                    SortExpression="DateProd" UniqueName="DateProd">
                </telerik:GridDateTimeColumn>
                
                <telerik:GridBoundColumn DataField="Couleur"
                    FilterControlAltText="Filter Couleur column" HeaderText="Couleur"
                    SortExpression="Couleur" UniqueName="Couleur">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="NumPlaque"
                    FilterControlAltText="Filter NumPlaque column" HeaderText="NumPlaque"
                    SortExpression="NumPlaque" UniqueName="NumPlaque">
                </telerik:GridBoundColumn>
                
                  <telerik:GridDateTimeColumn DataField="DateEnr" DataType="System.DateTime"
                    FilterControlAltText="Filter DateEnr column" HeaderText="DateEnr"
                    SortExpression="DateEnr" UniqueName="DateEnr">
                </telerik:GridDateTimeColumn>
                
                <telerik:GridBoundColumn DataField="IdUtilisateur" DataType="System.Int32"
                    FilterControlAltText="Filter IdUtilisateur column" HeaderText="IdUtilisateur"
                    SortExpression="IdUtilisateur" UniqueName="IdUtilisateur">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="Type"
                    FilterControlAltText="Filter Type column" HeaderText="Type"
                    SortExpression="Type" UniqueName="Type">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="NumChassi"
                    FilterControlAltText="Filter NumChassi column" HeaderText="NumChassi"
                    SortExpression="NumChassi" UniqueName="NumChassi">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="NombrePiston" DataType="System.Int32"
                    FilterControlAltText="Filter NombrePiston column" HeaderText="NombrePiston"
                    SortExpression="NombrePiston" UniqueName="NombrePiston">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="NombrePassager" DataType="System.Int32"
                    FilterControlAltText="Filter NombrePassager column" HeaderText="NombrePassager"
                    SortExpression="NombrePassager" UniqueName="NombrePassager">
                </telerik:GridBoundColumn>
                
                 <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                </telerik:GridEditCommandColumn>
                
                 <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
                                 
            </Columns>
            
            <EditFormSettings>
                <EditColumn ButtonType="ImageButton" />
            </EditFormSettings>
            
        </MasterTableView>
        
    </telerik:RadGrid>





and here is my datasource:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                   ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                   DeleteCommand="DELETE FROM [Voiture] WHERE [ID] = @ID"
                   InsertCommand="INSERT INTO [Voiture] ([Marque], [Model], [DateProd], [Couleur], [NumPlaque], [DateEnr], [IdUtilisateur], [Type], [NumChassi], [NombrePiston], [NombrePassager]) VALUES (@Marque, @Model, @DateProd, @Couleur, @NumPlaque, @DateEnr, @IdUtilisateur, @Type, @NumChassi, @NombrePiston, @NombrePassager)"
                   SelectCommand="SELECT * FROM [Voiture] ORDER BY [ID]"
                   UpdateCommand="UPDATE [Voiture] SET [Marque] = @Marque, [Model] = @Model, [DateProd] = @DateProd, [Couleur] = @Couleur, [NumPlaque] = @NumPlaque, [DateEnr] = @DateEnr, [IdUtilisateur] = @IdUtilisateur, [Type] = @Type, [NumChassi] = @NumChassi, [NombrePiston] = @NombrePiston, [NombrePassager] = @NombrePassager WHERE [ID] = @ID">
                       <DeleteParameters>
                           <asp:Parameter Name="ID" Type="Int32" />
                       </DeleteParameters>
                       <UpdateParameters>
                           <asp:Parameter Name="Marque" Type="String" />
                           <asp:Parameter Name="Model" Type="String" />
                           <asp:Parameter DbType="Date" Name="DateProd" />
                           <asp:Parameter Name="Couleur" Type="String" />
                           <asp:Parameter Name="NumPlaque" Type="String" />
                           <asp:Parameter DbType="Date" Name="DateEnr" />
                           <asp:Parameter Name="IdUtilisateur" Type="Int32" />
                           <asp:Parameter Name="Type" Type="String" />
                           <asp:Parameter Name="NumChassi" Type="String" />
                           <asp:Parameter Name="NombrePiston" Type="Int32" />
                           <asp:Parameter Name="NombrePassager" Type="Int32" />
                           <asp:Parameter Name="ID" Type="Int32" />
                       </UpdateParameters>
                       <InsertParameters>
                           <asp:Parameter Name="Marque" Type="String" />
                           <asp:Parameter Name="Model" Type="String" />
                           <asp:Parameter DbType="Date" Name="DateProd" />
                           <asp:Parameter Name="Couleur" Type="String" />
                           <asp:Parameter Name="NumPlaque" Type="String" />
                           <asp:Parameter DbType="Date" Name="DateEnr" />
                           <asp:Parameter Name="IdUtilisateur" Type="Int32" />
                           <asp:Parameter Name="Type" Type="String" />
                           <asp:Parameter Name="NumChassi" Type="String" />
                           <asp:Parameter Name="NombrePiston" Type="Int32" />
                           <asp:Parameter Name="NombrePassager" Type="Int32" />
                       </InsertParameters>
               </asp:SqlDataSource>
           
0
Shinu
Top achievements
Rank 2
answered on 10 Mar 2014, 05:27 AM
Hi Mike,

You code looks fine. I have tried a similar code and its working fine at my end. Please take a look at the below sample code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowAutomaticDeletes="True" AllowSorting="True" Skin="Metro" Width="100%">
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" HeaderText="OrderID" SortExpression="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" UniqueName="ShipName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" SortExpression="ShipVia" UniqueName="ShipVia">
            </telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" UniqueName="OrderDate">
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" UniqueName="ShipAddress">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
        </Columns>
        <EditFormSettings>
            <EditColumn ButtonType="ImageButton" />
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
    DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID" InsertCommand="INSERT INTO [Orders] ([OrderID], [ShipName], [ShipVia], [OrderDate], [ShipAddress]) VALUES (@OrderID, @ShipName, @ShipVia, @OrderDate, @ShipAddress)"
    SelectCommand="SELECT * FROM [Orders] ORDER BY [OrderID]" UpdateCommand="UPDATE [Orders] SET [ShipName] = @ShipName, [ShipVia] = @ShipVia, [OrderDate] = @OrderDate, [ShipAddress] = @ShipAddress WHERE [OrderID] = @OrderID">
    <DeleteParameters>
        <asp:Parameter Name="OrderID" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="ShipName" Type="String" />
        <asp:Parameter Name="ShipVia" Type="Int32" />
        <asp:Parameter DbType="Date" Name="OrderDate" />
        <asp:Parameter Name="ShipAddress" Type="String" />
        <asp:Parameter Name="OrderID" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="ShipName" Type="String" />
        <asp:Parameter Name="ShipVia" Type="Int32" />
        <asp:Parameter DbType="Date" Name="OrderDate" />
        <asp:Parameter Name="ShipAddress" Type="String" />
        <asp:Parameter Name="OrderID" Type="Int32" />
    </InsertParameters>
</asp:SqlDataSource>

You can also have a look at this online demo on Grid - Automatic Operations

Thanks,
Shinu
0
Amparo
Top achievements
Rank 1
answered on 23 Apr 2015, 04:06 PM

I am having similar problems with the update function. The Insert and Delete Functions work perfectly though...

Please see my code below. Please advise. Thanks!

<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="false" ShowStatusBar="true"
                                AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" Width="100%" Skin="Bootstrap"
                                DataSourceID="CoSqlDataSource">
                                <MasterTableView Width="100%" CommandItemDisplay="Bottom" DataKeyNames="Com_Num,Com_Name"
                                    InsertItemPageIndexAction="ShowItemOnCurrentPage"
                                    InsertItemDisplay="Top">
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton" 
                                            CancelImageUrl="App_Themes/Clear/images/Cancel.png" 
                                            EditImageUrl="App_Themes/Clear/images/Edit.png"
                                            UpdateImageUrl="App_Themes/Clear/images/Update.png" >
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridBoundColumn UniqueName="Com_Num" HeaderText="Company Number" DataField="Com_Num"
                                            HeaderStyle-Wrap="false" MaxLength="2" ItemStyle-HorizontalAlign="Center" DataType="System.Int32" >
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn UniqueName="Com_Name" HeaderText="Company Name" DataField="Com_Name" 
                                            ItemStyle-Wrap="false" MaxLength="50">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
                                            ConfirmText="Delete this Company?" ConfirmDialogType="RadWindow"
                                            ConfirmTitle="Delete" ImageUrl="App_Themes/Clear/images/Delete.png" ButtonType="ImageButton" >
                                        </telerik:GridButtonColumn>
                                    </Columns>
                                    <EditFormSettings>
                                        <EditColumn ButtonType="ImageButton" EditImageUrl="App_Themes/Clear/images/Edit.png" 
                                            CancelImageUrl="App_Themes/Clear/images/Cancel.png" UpdateImageUrl="App_Themes/Clear/images/Update.png"
                                             InsertImageUrl="App_Themes/Clear/images/Update.png" />
                                    </EditFormSettings>
                                    <CommandItemSettings AddNewRecordText="Add new record" AddNewRecordImageUrl="App_Themes/Clear/images/AddRecord.png"
                                        RefreshText="Refresh" RefreshImageUrl="App_Themes/Clear/images/Refresh.png"
                                        ></CommandItemSettings>
                                </MasterTableView>
                            </telerik:RadGrid>
                            <asp:SqlDataSource ID="CoSqlDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:csm_cdw_db_ConnectionString %>'
                                SelectCommand="SELECT DISTINCT [Com_Num], [Com_Name] FROM [PNS].[Company_Number] ORDER BY [Com_Num]"
                                InsertCommandType="Text" InsertCommand="INSERT INTO [pns].[Company_Number] ([Com_Num],[Com_Name]) VALUES(@Com_Num, @Com_Name)"
                                DeleteCommandType="Text" DeleteCommand="DELETE FROM [pns].[Company_Number] WHERE [Com_Num] = @Com_Num"
                                UpdateCommandType="Text" 
                                UpdateCommand="UPDATE [pns].[Company_Number] SET [Com_Name] = @Com_Name WHERE [Com_Num] = @Com_Num">
                                <InsertParameters>
                                    <asp:Parameter Name="Com_Num"  Size="2" />
                                    <asp:Parameter Name="Com_Name" Type="String" Size="50" />
                                </InsertParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="Com_Num"  Size="2" Type="Int32" />
                                    <asp:Parameter Name="Com_Name" Type="String" Size="50" />
                                </UpdateParameters>
                                <DeleteParameters>
                                    <asp:Parameter Name="Com_Num"  Size="2" />
                                </DeleteParameters>
                            </asp:SqlDataSource>

 

 

0
Maria Ilieva
Telerik team
answered on 28 Apr 2015, 08:19 AM
Hello Amparo,

I would suggest you to inspect your page and check if any js errors appear on the page when you are attempting to update a record. In most of the cases this is the reason for the issue you are facing.

Regards,
Maria Ilieva
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Mike McCoy
Top achievements
Rank 1
Answers by
Mike McCoy
Top achievements
Rank 1
Rosen
Telerik team
Siraj
Top achievements
Rank 1
Tan
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Amparo
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or