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

Server Batch Update without command Column

4 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 29 Jul 2010, 09:21 PM
I have a telerik radgrid with a single editable column that I've thrown into edit mode using the code below.  I'm using a radtoolbar and I'd like to allow the user to save the grid data (AllowMultiRowEdit="true") without requiring a per-row or even grid-specific update button.  All of the examples seem to be pulling necessary objects from the eventArgs.  Is there a grid example that allows me to process the grid changes from a separate toolbar button?

protected void LUOGrid_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        foreach (GridItem item in LUOGrid.MasterTableView.Items)
        {
            if (item is GridEditableItem)
            {
                GridEditableItem editableItem = item as GridDataItem;
                editableItem.Edit = true;
            }
        }
        LUOGrid.Rebind();
    }
}

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2010, 07:49 AM
Hello Daniel,

You can follow this documentation Performing batch updates and extract the new values using LUOGrid.MasterTable.ExtractValuesFromItem instead of e.Item.OwnerTableView.ExtractValuesFromItem.

Check out the sample code below.

C#:
protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
{
 foreach (GridEditableItem editedItem in Grid1.EditItems)
  {              
    System.Collections.Hashtable newValues = new System.Collections.Hashtable();
    //The GridTableView will fill the values from all editable columns in the hash
    LUOGrid.MasterTableView.ExtractValuesFromItem(newValues, editedItem);
    string value = newValues["ColumnUniqueName"].ToString(); //get the value using 'ColumnUniqueName'
    //sql query for updation
    editedItem.Edit = false;
   }
  LUOGrid.Rebind();
 }

Thanks,
Princy.
0
Daniel
Top achievements
Rank 1
answered on 30 Jul 2010, 01:17 PM
That did the trick, thanks.
0
Daniel
Top achievements
Rank 1
answered on 30 Jul 2010, 03:15 PM
One more thing in this method - how do you access the other column in the grid to inspect their values?  I was able to retrieve key values using
string reserveCategoryCode = LUOGrid.MasterTableView.DataKeyValues[editedItem.RowIndex]["ReserveCategoryCode"].ToString();

When I try to access another field that is not a key value using the code described in "accessing cells and rows", the text property returns a non-breaking space ( ) despite the fact that the cell has a value on the screen

GridDataItem item = LUOGrid.MasterTableView.Items[editedItem.RowIndex];
decimal currentLUOAmount = Convert.ToDecimal(item["LUOAmountColumn"].Text); // returns  
0
Princy
Top achievements
Rank 2
answered on 02 Aug 2010, 07:05 AM
Hello Daniel,

If you want to extract the new values from the edited table row, then better option is using 'extractValuesFromItem' method.

For this approach, create an empty dictionary object and pass it as the first parameter of the ExtractValuesFromItem method and pass the edited item as the second parameter. The ExtractValuesFromItem  method fills the dictionary object with key/value pairs where each key  is the DataField of an edited field column and the corresponding value is the new data entered by the user.

Here is an example:
C#:
System.Collections.Hashtable newValues = new System.Collections.Hashtable();
LUOGrid.MasterTableView.ExtractValuesFromItem(newValues, editedItem);
string value = newValues["LUOAmountColumn"].ToString();// getting NewValue in column 'LUOAmountColumn'
decimal currentLUOAmount = Convert.ToDecimal(value);

For more information, check this: Updating values in-place and with edit forms 

Thanks,
Princy.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Share this question
or