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

Mass update on grid

5 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 22 Sep 2009, 06:57 PM
I was reviewing another set of ASP.net controls and they provide the ability to Mass update their grid.  An example would be that I have a grid populated with data.  I would like to use an outside form to find all values in the grid that are X and replace it with Y.  Is that possible with the RadGrid?  If so, is there an example?

5 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 23 Sep 2009, 02:50 AM
Hello Chris-

Thanks for taking the time to explore the RadGrid. I'm not sure I 100% understand the scenario you're trying to support. Do you want to be able to "mass update" all values for a single record? Or are you interested in updating all values for all rows and columns at one time?

There are lots of demos showing you how to work with RadGrid data editing online. Two that may be relevant here:

This demo shows you how you can use an "external form" to edit a grid record. The form can obviously take any shape you desire, so this may support your search and replace scenario.

This page from the online docs describes the process for performing "batch updates" with RadGrid. Essentially, this allows you to edit all rows in a grid at one time and then save the changes (perhaps the "mass update" you're looking for). There is a supporting Code Library project showing you how to use RadGrid in an "excel-like" mode (all cells editable) here:

Hope that helps! Feel free to redirect if I've missed the scenario you're after.
-Todd
0
Chris
Top achievements
Rank 1
answered on 23 Sep 2009, 11:33 PM
This is close, but I really looking for something like another post I saw.  What I would like to do is loop through all the values of a Column and replace the text value with another text value.  For instance, lets say I have a column in my RadGrid that is called Color.  Some of the values are red and some are green and some are yellow.  I would like to have a text box called "Find" in which case on click of a button it loops through all the Column cells for Color to "Find" red. I then want another text box called "Replace" which replaces all cells in Column Color with value blue. 

This code from another post is close but not enough for me to understand how to make it work.

Generally SelectedItems is a collection of GridDataItem and you can index this type by column UniqueName. Here is an example for SelectedIndexChanged event:

foreach(GridDataItem item in RadGrid1.SelectedItems)
{
    foreach(GridColumn column in item.OwnerTableView.RenderColumns)
    {
       Response.Write(String.Format("{0} : {1} <br />", column.UniqueName, item[column.UniqueName].Text));
    }
}

Does this make sense?
0
Todd Anglin
Top achievements
Rank 2
answered on 24 Sep 2009, 02:55 AM
Thanks for the extra info! That really helps clarify what you're trying to do.

There is one other critical piece of the puzzle that will help. Do you want this search/replace to happen client-side with JavaScript or do want it to happen server-side? Also, do want this change to update the data source or only update the "displayed" data in RadGrid?

If it is the later and you want to update the data on the server, I think this may not require any RadGrid API involvement. You should be able to easily grab the "Find" term and "Replace" term on PostBack and then perform an update on your data source (for example, UPDATE tblName SET colorName = '{yourReplaceTerm}' WHERE colorName = '{yourFindTerm}'). Once that's done, a "normal" rebind of the grid will display the updated values.

Let me know if you're after something more complex than that and I'll be happy to provide additional input.

-Todd
0
Chris
Top achievements
Rank 1
answered on 24 Sep 2009, 03:33 AM
Actually I would prefer doing the update on the client side. I have some validation that needs to fire when actually saving to the database, which occurs on another button click.  I have been trying to use javascript to isolate the elements, but I'm not having much luck.  If you have any examples, I would love to see them.
0
Sebastian
Telerik team
answered on 29 Sep 2009, 06:33 AM

Hello Chris,

Client-side updates are possible with an external edit form and client-side binding for the grid as presented on this online demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx

If this approach is applicable for your case, feel free to use it. Alternatively, you can utilize server-side updates and ajaxify the grid via RadAjaxManager or RadAjaxPanel to simulate client-side performance.

Best regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or