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

problem with GridBoundColumn

3 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
esmyy
Top achievements
Rank 1
esmyy asked on 08 Feb 2012, 02:59 PM
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

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 08 Feb 2012, 04:36 PM
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 >>
0
esmyy
Top achievements
Rank 1
answered on 08 Feb 2012, 05:00 PM
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
0
Andrey
Telerik team
answered on 09 Feb 2012, 04:11 PM
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 >>
Tags
Grid
Asked by
esmyy
Top achievements
Rank 1
Answers by
Andrey
Telerik team
esmyy
Top achievements
Rank 1
Share this question
or