RadGrid Update Command Not Working-Please help!

9 posts, 0 answers
  1. Mike McCoy
    Mike McCoy avatar
    3 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    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

  2. Mike McCoy
    Mike McCoy avatar
    3 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Nobody can tell me what I am doing wrong there or at least point me in the right direction?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 11 Jun 2010 Link to this post

    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.
  5. Siraj
    Siraj avatar
    3 posts
    Member since:
    Jan 2012

    Posted 06 Feb 2012 Link to this post

    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
  6. Tan
    Tan avatar
    17 posts
    Member since:
    Feb 2012

    Posted 18 Mar 2012 Link to this post

    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.
    ^^
  7. Mike
    Mike avatar
    3 posts
    Member since:
    Sep 2013

    Posted 08 Mar 2014 Link to this post

    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>
               
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2014 in reply to Mike Link to this post

    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
  9. Amparo
    Amparo avatar
    3 posts
    Member since:
    Dec 2014

    Posted 23 Apr 2015 in reply to Shinu Link to this post

    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>

     

     

  10. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 28 Apr 2015 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017