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

how to get RadGrid cell value aftter changing it.

6 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emanuil
Top achievements
Rank 1
Emanuil asked on 24 Feb 2011, 03:10 PM

Hello, I use RadGrid in edit mode and I want to get cell value after changing it.

When I use UpdateCommand event, I get old value before changing.

 

 

protected

 

 

void gridEdit_UpdateCommand(object sender, GridCommandEventArgs e)

 

 

{

 

 

 

    GridEditableItem editItem = (GridEditableItem)e.Item;

 

 

 

 

    //TextBox txtbox = (TextBox)editItem["Value"].Controls[0]; //access the value

 

 

 

 

    string value = (editItem["Value"].Controls[0] as TextBox).Text;

 

 

 

 

}

 

 

 

 

<telerik:RadGrid ID="gridEdit" runat="server" GridLines="None"

 

 

 

 

 

onupdatecommand="gridEdit_UpdateCommand"

 

 

 

<MasterTableView

 

 

 

 

 

EditMode="InPlace">

 

 

 

 

 

<Columns>

 

 

 

 

 

<telerik:GridEditCommandColumn />

 

 

 

 

 

</Columns>

 

 

 

 

 

</MasterTableView>
</telerik:RadGrid>

 

 

 

 

 

 

 

 

 

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Feb 2011, 03:41 PM
Hello Emanuil,

Please refer to this help topic for more information how to achieve the desired by you functionality.

Greetings,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Emanuil
Top achievements
Rank 1
answered on 24 Feb 2011, 04:00 PM
Yes, I have reviewed the article, but I want to get value after changing the the textbox in cell.
I click the edit link on the row, after that changing the value of editable column and then click update link but I continue to have the old value.
0
Princy
Top achievements
Rank 1
answered on 25 Feb 2011, 06:09 AM
Hello Emanuil,

Can you please check whether you have tried the following code as descrides in the above help topic.

ASPX:
<telerik:GridBoundColumn DataField="FirstName"  UniqueName="FirstName">
</telerik:GridBoundColumn>

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem editedItem = e.Item as GridEditableItem;
       Hashtable newValues = new Hashtable();
       e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
       string v=  newValues["FirstName"].ToString();//getting new value
   }

Also verify that the ViewState of the RadGrid is enabled. Because if you  set EnableViewState="false" , you will not get the new value.

Thanks,
Princy.
0
Emanuil
Top achievements
Rank 1
answered on 25 Feb 2011, 08:54 AM
Hello Princy, I have tried the code but I continue to get the old value.
0
Accepted
Pavlina
Telerik team
answered on 25 Feb 2011, 02:09 PM
Hi Emanuil,

Attached to this message is a sample project which handles the desired functionality. Give it a try and let me know if it helps to resolve the problem.

Greetings,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jorge
Top achievements
Rank 1
answered on 24 Jun 2013, 04:28 AM
How do you do it for editmode="batch"? Where I can edit mutiple cells by clicking on them?

For example, the following code doesn't give me the  new values i entered into the cells ... I  get the old values (from db).

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            Hashtable newValues = new Hashtable();
            //The GridTableView will fill the values from all editable columns in the hash
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, item);
 
            var customerID = item.GetDataKeyValue("CustomerID").ToString();
            Customer customer = DB.Customers.Where(p => p.CustomerID == customerID).FirstOrDefault();           
            customer.CompanyName = newValues["CompanyName"].ToString();
            DB.SaveChanges();
            SetMessage("Customer updated!");
        }

Thanks in advance.

Jorge

Tags
Grid
Asked by
Emanuil
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Emanuil
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Jorge
Top achievements
Rank 1
Share this question
or