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

How best to implement custom command that modifies data in the grid

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 13 Jan 2011, 03:47 PM
Hi. I have a RadGrid that will display some records from a database table (using an sqldatasource). The user can edit and add records as normal. However, there is one field (called "default") which has special conditions associated with it. For a given set of records, only one record should have default=true.

I want to set client select = true such that only one record can be selected at a time (which is easy to do on the RadGrid). Then in the commandItem I want to add a button for a custom command "SetDefault". I am happy doing all of that - no problems.

My question relates to the code behind for the custom command "SetDefault". I can see three ways of doing what I want and would appreciate any view/comment about the best solution. If I do it within the Grid I am not sure how best to implement it. Options I can see are:

1. in the code use a datacontext and then a program loop to modify each of the records (easy to do) and I then assume I will need to refresh the grid.

2. somehow use an sql update query to update all of the records necessary (I can write the sql update query but I don't know how to execute a query from code) and then again refresh the grid

3. somehow process the RadGrid from the code that implements the custom command. This will have to do a foreach (GridDataItem item in RadGrid1.Items) loop that then modifies the value of a column in the grid. Questions: do I need to put each item into edit mode? How do I reference a column from the code to modify it's value? What do I need to do to then save the modified value? I am concerned that this approach will be slower than either of the previous two options - hence my question


Does this make sense?

1 Answer, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 18 Jan 2011, 01:04 PM
Hello Paul,

Indeed, what you should do, is to perform database update and then rebind the grid. You can create a stored procedure which will perform the database updates and call it in the grid ItemCommand event handler. You can find more information on how to make the database operations in msdn for instance.

Kind regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or