Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > problem with GridBoundColumn

Not answered problem with GridBoundColumn

Feed from this thread
  • esmyy avatar

    Posted on Feb 8, 2012 (permalink)

    Hi,
    I'm using a SqlDataSource for my RadGrid and I can't edit the data, it's not updating in my database.
    What do I have to add to my code?


    Thanks in advance,
    esmyy

    Reply

  • Andrey Andrey admin's avatar

    Posted on Feb 8, 2012 (permalink)

    Hello,

    If you want to use Automatic CRUD operations with RadGrid, there are two steps that you need to perform:

    • Set AllowAutomaticUpdates property of RadGrid to true.
    • Provide an Update statement in the SqlDataSource control.

    You could check this online to get an overview how your Grid declaration should look like after you performed these steps.

    If you wan to use Manual CRUD operations you need to set AllowAutomaticUpdates to false and then hook the OnUpdateCommand event of RadGrid. In its body you should perform the SQL update operation. You could check this help topic for more information.

    Give this suggestion a try and check whether the issue is resolved.

    Regards,
    Andrey
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • esmyy avatar

    Posted on Feb 8, 2012 (permalink)

    Hi Andrey
    Thank you, it's working now, but if I update 1 field in 1 row it's updating the same field in every row!
    Why does it make the changes in every row?

    Regards, esmyy

    Reply

  • Andrey Andrey admin's avatar

    Posted on Feb 9, 2012 (permalink)

    Hi,

    You are observing this behavior, because most probably you have forgotten to limit the updated rows with the "WHERE" clause. If you omit the "WHERE" clause this will initiate update to all records in the database.

    In the demo I have sent you in my last reply, the UpdateCommand looks like this:

    UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice, [Discontinued] = @Discontinued, [QuantityPerUnit] = @QuantityPerUnit, [UnitsInStock] = @UnitsInStock WHERE [ProductID] = @ProductID">

    You could see that we are using WHERE statement to limit the affected records. The @"FieldName" statement are UpdateParameters that are listed in the UpdateParameters collection in the DataSource declaration:

    <UpdateParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="CategoryID" Type="Int32" />
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="Discontinued" Type="Boolean" />
                <asp:Parameter Name="QuantityPerUnit" Type="String" />
                <asp:Parameter Name="UnitsInStock" Type="Int16" />
                <asp:Parameter Name="ProductID" Type="Int32" />
            </UpdateParameters>

    You could check this MSDN thread for more information about the Update operation with SqlDataSource. More information about the Update statement that is used could be found in this MSDN thread.

    Regards,
    Andrey
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > problem with GridBoundColumn
Related resources for "problem with GridBoundColumn"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]