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

Radgrid update command not updating

4 Answers 35 Views
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 1
Robin asked on 28 Aug 2018, 05:50 PM

I have a radgrid with Allow automaticupdates but when I try it it does update the database below is my asp.net code

<%@ Page Title="" Language="VB" MasterPageFile="~/Header.master" AutoEventWireup="false" CodeFile="InvoiceSchedule.aspx.vb" Inherits="StepIII_InvoiceSchedule" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>


  
   <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js"></asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js"></asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js"></asp:ScriptReference>
        </Scripts>
      
    </telerik:RadScriptManager>

 

<div class="Invoice">

       <%-- Created a gridview that has templates --%>
         
          <asp:SqlDataSource ID="sqlMonth" runat="server" ConnectionString="<%$ ConnectionStrings:COSIGrantsDB %>" SelectCommand="SELECT * FROM [lkp_Month]"></asp:SqlDataSource>
          <asp:SqlDataSource ID="sqlYear" runat="server" ConnectionString="<%$ ConnectionStrings:COSIGrantsDB %>" SelectCommand="SELECT * FROM [lkp_Year]"></asp:SqlDataSource>
          <asp:SqlDataSource ID="sqlInvoiceSource" runat="server" ConnectionString="<%$ ConnectionStrings:COSIGrantsDB %>" SelectCommand="SELECT SourceID as SID, Source AS invoicesource FROM lkp_InvoiceSource"></asp:SqlDataSource>
          <asp:SqlDataSource runat="server" ID="sqlInvoice" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="SELECT InvoiceSchedule_Test.Amount, lkp_Month.Month, InvoiceSchedule_Test.MonthId, InvoiceSchedule_Test.YearId, InvoiceSchedule_Test.SourceId, lkp_Year.Year, lkp_InvoiceSource.Source, InvoiceSchedule_Test.ApplicationID, InvoiceSchedule_Test.InvoiceScheduleId FROM InvoiceSchedule_Test LEFT OUTER JOIN lkp_Month ON InvoiceSchedule_Test.MonthId = lkp_Month.MonthID LEFT OUTER JOIN lkp_Year ON InvoiceSchedule_Test.YearId = lkp_Year.YearID LEFT OUTER JOIN lkp_InvoiceSource ON InvoiceSchedule_Test.SourceId = lkp_InvoiceSource.SourceID WHERE (InvoiceSchedule_Test.ApplicationID = @AppID)" InsertCommand="INSERT INTO InvoiceSchedule_Test(MonthId, YearId, Amount, SourceId, ApplicationID) VALUES (@monthid, @yearid, @amount, @sourceid, @appid)" DeleteCommand="Delete from InvoiceSchedule_test where invoicescheduleid=@invoiceid" UpdateCommand="UPDATE InvoiceSchedule_Test SET MonthId = @monthid, YearId = @yearid, Amount = @amount, SourceId = @sourceid, ApplicationID = @appid WHERE (InvoiceScheduleId = @invoiceschedid)">

              <DeleteParameters>
                  <asp:Parameter Name="invoiceid"></asp:Parameter>
              </DeleteParameters>
              <InsertParameters>
                  <asp:Parameter Name="monthid"></asp:Parameter>
                  <asp:Parameter Name="yearid"></asp:Parameter>
                  <asp:Parameter Name="amount"></asp:Parameter>
                  <asp:Parameter Name="sourceid"></asp:Parameter>
                  <asp:SessionParameter SessionField="appid" Name="AppID" Type="Int32"></asp:SessionParameter>
              </InsertParameters>
              <SelectParameters>
                  <asp:SessionParameter SessionField="appid" Name="AppID" Type="Int32"></asp:SessionParameter>
              </SelectParameters>
              <UpdateParameters>
                  <asp:Parameter Name="monthid"></asp:Parameter>
                  <asp:Parameter Name="yearid"></asp:Parameter>
                  <asp:Parameter Name="amount"></asp:Parameter>
                  <asp:Parameter Name="sourceid"></asp:Parameter>
                  <asp:SessionParameter SessionField="appid" Name="AppID" Type="Int32"></asp:SessionParameter>
           <asp:Parameter Name="invoiceschedid" />
                     </UpdateParameters>


          
          </asp:SqlDataSource>
          <telerik:RadGrid ID="rg" runat="server" AutoGenerateEditColumn="True" DataSourceID="sqlInvoice" AutoGenerateDeleteColumn="True" AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True">

<GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>

              <MasterTableView DataKeyNames="InvoiceScheduleId" DataSourceID="sqlInvoice" AutoGenerateColumns="False" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" CommandItemDisplay="top">
                  <Columns>
                      <telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" SortExpression="Amount" UniqueName="Amount" DataType="System.Decimal" FilterControlAltText="Filter Amount column"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="Month" HeaderText="Month" SortExpression="Month" UniqueName="Month" FilterControlAltText="Filter Month column"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="MonthId" HeaderText="MonthId" SortExpression="MonthId" UniqueName="MonthId" DataType="System.Int32" FilterControlAltText="Filter MonthId column"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="YearId" HeaderText="YearId" SortExpression="YearId" UniqueName="YearId" FilterControlAltText="Filter YearId column" DataType="System.Int32"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="SourceId" HeaderText="SourceId" SortExpression="SourceId" UniqueName="SourceId" FilterControlAltText="Filter SourceId column"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="Year" HeaderText="Year" SortExpression="Year" UniqueName="Year" DataType="System.Int32" FilterControlAltText="Filter Year column"></telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="Source" FilterControlAltText="Filter Source column" HeaderText="Source" SortExpression="Source" UniqueName="Source">
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="ApplicationID" DataType="System.Int32" FilterControlAltText="Filter ApplicationID column" HeaderText="ApplicationID" SortExpression="ApplicationID" UniqueName="ApplicationID">
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="InvoiceScheduleId" DataType="System.Int32" FilterControlAltText="Filter InvoiceScheduleId column" HeaderText="InvoiceScheduleId" ReadOnly="True" SortExpression="InvoiceScheduleId" UniqueName="InvoiceScheduleId">
                      </telerik:GridBoundColumn>
                  </Columns>
              </MasterTableView>
          </telerik:radgrid>
       <%--   <telerik:RadGrid ID="rg" runat="server" AutoGenerateDeleteColumn="True" allowautomaticdeletes="true" AutoGenerateEditColumn="True" DataSourceID="sqlInvoice" AllowAutomaticInserts="True" onUpdateCOmmand="rg_Update" AutoGenerateColumns="False" CellSpacing="-1" GridLines="Both" onDeleteCommand="rg_DeleteCommand"  >



            <MasterTableView DataKeyNames="InvoiceScheduleId" DataSourceID="sqlInvoice" commanditemdisplay="top" >
                   <Columns>
                         <telerik:GridBoundColumn HeaderText="invoiceid" datafield="invoicescheduleid"></telerik:GridBoundColumn>
                
                         <telerik:GridTemplateColumn DataField="source" FilterControlAltText="Filter Invoicesource column" HeaderText="source" UniqueName="Invoicesource">
                             <EditItemTemplate>
                                 <asp:DropDownList ID="sourceDropDownList" runat="server" DataSourceID="sqlInvoiceSource" DataTextField="invoicesource" DataValueField="sid">
                                 </asp:DropDownList>
                             </EditItemTemplate>
                             <ItemTemplate>
                                 <asp:Label ID="sourceLabel" runat="server" Text='<%# Eval("source") %>'></asp:Label>
                             </ItemTemplate>
                         </telerik:GridTemplateColumn>
          
                
                       <telerik:GridDropDownColumn DataField="monthid"   HeaderText="Month" uniquename="monthid" ListTextField="Month" ListValueField="monthid" datasourceid="sqlMonth"></telerik:GridDropDownColumn>
                       <telerik:griddropdowncolumn uniqueName="yearid" ListTextField="year" ListValueField="yearid" DataSourceID="sqlYear" HeaderText="Year" DataField="yearid"></telerik:griddropdowncolumn>
                       <telerik:gridboundcolumn UniqueName="amount" HeaderText="amount" Dataformatstring="{0:C}" DataField="amount"></telerik:gridboundcolumn>
                         
                     
            
                         
                     
                    
               
                   </Columns>
               </MasterTableView>
           </telerik:RadGrid>
       --%>
          
             </div>

 

Can anyone tell me what I am doing wrong?

Thanks

 

Robin 

4 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 31 Aug 2018, 09:50 AM
Hi Robin,

The code snippet you have provided seems to be appropriate. To narrow down the issue I would advise you disable AJAX temporarily if present. If there are server errors, they are most likely to be hidden. To get more details about the errors, you can follow the Get more descriptive errors by disabling AJAX article.

The code you've shared with us seems to use Master/Content pages, but the ScriptManager is on the content page. We recommend that you place the RadScriptManager on the MasterPage and use ScriptManagerProxy on the content pages. (see There is not RadScriptManagerProxy, what should I do?). You can also try removing the AjaxToolkit as it is no longer compatible with RadScriptManager. (see The RadScriptManager is incompatible with the Ajax Control Toolkit (Version number 40412 and higher))

If you're done with the steps from above, try to run a query manually to see whether it will succeed. Most of times the issue lies in the query.

In addition to the above steps, please also check out the UpdateParameters section of the SqlDataSource and try to define a DbType for each parameter.

Here is an example:
<UpdateParameters>
    <asp:Parameter Name="OrderDate" DbType="DateTime" />
    <asp:Parameter Name="Freight" DbType="Decimal" />
    <asp:Parameter Name="ShipName" DbType="String" />
    <asp:Parameter Name="ShipCountry" DbType="String" />
</UpdateParameters>

Attached you can find a sample project demonstrating Automatic CRUD operations with SqlDataSource. Please check it out and eventually compare it to your project to see what is done differently. 

If the issue still persist, I advise you modify my sample to produce the error and send it back to us for further investigation. You can also export the database and include that in the project. Here is an article that can guide you though this process: Import and Export SQL database to *.sql script via SQL Management Studio (note that the data is not require, you may export only the structure)

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Robin
Top achievements
Rank 1
answered on 31 Aug 2018, 06:10 PM
Thanks for the info.. I am still working on it. I havent used a Scriptmanager proxy before.  What do  I put in the tag?
0
Robin
Top achievements
Rank 1
answered on 31 Aug 2018, 09:21 PM

I havent had any luck.  I think it has to do with the dropdownlist that I am trying to use for Month, year, Source.  When I remove those the update works for Amount. When I add one back in it no longer works.

Here is what I tried that you asked

1. Update query works fine on its own

2. Removed Ajaxtoolkit

3, Compared to your example,  mine has drop downs and that is where it fails

My goal is to have a grid with dropdownlist options in edit and inster for Month, Year and Source. 

Thanks

 

0
Attila Antal
Telerik team
answered on 05 Sep 2018, 04:17 PM
Hi Robin,

If you prefer the render different script depending on the content page, you can use the ScriptManagerProxy to do so. You can check out the following article explaining the usage and difference of ScriptManager and ScriptManagerProxy: What is the Difference Between Script Manager and Script Manager Proxy

Regarding the update issue, if binding is done differently with GridDropDownColumn or DropDownList inside a GridTemplateColumn, the Grid will send not send any value in the Update values, hence the SqlDataSource will overwrite the existing data with empty string (wipe the cell).

Solution would be, if using dropdown column please ensure that the DataField, DataSourceID and ListValueField properties are set as described in the GridDropDownColumn article. For updating the grid using MS DropDown in a template column, you can refer to the following article address this scenario: Operations with MS DropDownList in EditItemTemplate of GridTemplateColumn

This will do the trick.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Robin
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Robin
Top achievements
Rank 1
Share this question
or