GridBoundColumn not updating w/ new value

2 posts, 0 answers
  1. ToltingColtAcres
    ToltingColtAcres avatar
    92 posts
    Member since:
    Nov 2010

    Posted 16 Sep 2018 Link to this post

    I have a Grid with a Binary Image and a Description field. Inserts work great, both binary image and description are saved correctly.

    On updates, though, the description field is not getting updated, the "old" value is passed to the SqlDataSource, not the new edited value from the grid.

    In other words... I add a record, with an image and a description (say, 'testing'). Verified it is saved in the database correctly (query in SQL Management Studio).

    I then edit the record and change the description to 'Testing1234', tab off description field, click save, the new value is not saved, the old value 'testing' is.

    I added some code to the SQL Datasources' OnInserting and OnUpdating events (see code below.)

    On insert, the value of the @Description parameter is 'Testing' (when Testing is typed in the description.)

    On update, changing the value in the Grid to 'Testing1234' and clicking the save button yields 'Testing' for the value of the @Description parameter in the OnUpdating event, not the new 'Testing1234' value entered in the Grid.

    Any thoughts on why this is happening would be helpful. I've been staring at it now for 6 hours w/ no success, and other, similar Grids work fine (although this is my only grid which uses an Binary Image.)

     

    My code:

    <asp:SqlDataSource ID="SqlDataSource_Receipts" runat="server"
        ConflictDetection="CompareAllValues"
        OnInserting="SqlDataSource_Receipts_Inserting"
        OnUpdating="SqlDataSource_Receipts_Updating"
        ConnectionString="<%$ ConnectionStrings:Receipts %>"
        DeleteCommand="DELETE FROM Receipts WHERE Receipt_GUID = @Receipt_GUID"
        InsertCommand="INSERT INTO Receipts (Receipt_GUID, Employee_GUID, Description, ReceiptImage) VALUES (NEWID(), @Employee_GUID, @Description, @ReceiptImage)"
        SelectCommand="SELECT * FROM Receipts WHERE Employee_GUID = @Employee_GUID"
        UpdateCommand="UPDATE Receipts  SET Description = @Description, ReceiptImage = CASE WHEN ISNULL(DATALENGTH(CONVERT(varbinary(MAX), @ReceiptImage)), -1) = -1 THEN ReceiptImage ELSE CONVERT(VARBINARY(MAX), @ReceiptImage) END WHERE Receipt_GUID = @Receipt_GUID">
        <DeleteParameters>
            <asp:Parameter Name="Receipt_GUID" />
        </DeleteParameters>
        <InsertParameters>
            <asp:ControlParameter ControlID="RadGrid_Employees" Name="Employee_GUID" PropertyName="SelectedValues['Employee_GUID']" DbType="Guid" />
            <asp:Parameter Name="Description" />
            <asp:Parameter Name="ReceiptImage" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="RadGrid_Employees" Name="Employee_GUID" PropertyName="SelectedValues['Employee_GUID']" DbType="Guid" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Receipt_GUID" />
            <asp:Parameter Name="Description" />
            <asp:Parameter Name="ReceiptImage" />
        </UpdateParameters>
    </asp:SqlDataSource>

     

    The radgrid definition:

    <telerik:RadGrid ID="RadGrid_Receipts" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource_Receipts" GridLines="None" Width="100%" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowAutomaticDeletes="True" AllowSorting="True" OnItemDataBound="RadGrid_Receipts_ItemDataBound" CellSpacing="0" ShowStatusBar="True" ShowFooter="true" AutoGenerateDeleteColumn="False" AutoGenerateEditColumn="False">
     <MasterTableView CommandItemDisplay="Bottom" AllowPaging="True" EditMode="InPlace" DataKeyNames="Receipt_GUID, Employee_GUID">
      <Columns>
       <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
        <HeaderStyle Width="50px" />
        <ItemStyle CssClass="MyImageButton" Width="50px" />
       </telerik:GridEditCommandColumn>
       <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmText="Delete this Receipt?" ConfirmTitle="Delete" Text="Delete" UniqueName="DeleteColumn">
        <HeaderStyle Width="25px" />
        <ItemStyle CssClass="MyImageButton" HorizontalAlign="Center" Width="25px" />
       </telerik:GridButtonColumn>
       <telerik:GridBinaryImageColumn DataField="ReceiptThumb" HeaderText="Receipt Image" UniqueName="ReceiptThumb" ResizeMode="Fit" ImageWidth="100" ImageHeight="100"  />
       <telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description" ItemStyle-Width="500px" HeaderStyle-HorizontalAlign="Center" />
      </Columns>
     </MasterTableView>
    </telerik:RadGrid>

    My Datasource onInserting/Updating events:

    protected void SqlDataSource_Receipts_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
          SqlParameter d = (SqlParameter)e.Command.Parameters["@Description"];
          // d.Value = 'Testing' , correct, this is what I enter on the form.
    }
    protected void SqlDataSource_Receipts_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
          SqlParameter d = (SqlParameter)e.Command.Parameters["@Description"];
          // d.Value = 'Testing' despite having typed 'Testing1234' in the RadGrid before clicking Save
    }
  2. Eyup
    Admin
    Eyup avatar
    3756 posts

    Posted 14 Nov 2018 Link to this post

    Hi Michael,

    You can try removing the ConflictDetection property of the SqlDataSource to see if that resolves the issue:
    SqlDataSource.ConflictDetection Property

    Also, it seems that you have some specific UpdateCommand definition. For testing purpose you can simplify it and try to update only the Description and including the where part. Once you verify that updating actually works, you can gradually continue to configure the composition of the UpdateCommand statement.

    If the issue remains, you can open a formal support ticket and send us a very basic runnable web site to demonstrate the described issue. This will enable us to replicate the problem locally and provide more accurate and precise suggestions.

    Regards,
    Eyup
    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.
Back to Top