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

new value for cell in edit mode?

2 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FADI
Top achievements
Rank 1
FADI asked on 04 Jun 2009, 03:42 PM
Hi

If Radgrid in edit mode i would like to know how can i get the new value intered by user in cell ?

thanks

Fadi

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jun 2009, 04:35 AM
Hi Fadi,

Try the following code snippet for accessing the edited value in UpdateCommand.

CS:
 
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        GridEditableItem item = (GridEditableItem)e.Item; 
        TextBox txtBox = (TextBox)item["OrderID"].Controls[0];  
        Response.Write(txtBox.Text);  // Edited value for OrderID column 
    } 

You can also access the edited value in the buttonclick event where the button is placed outside the grid.
CS:
 
protected void Button2_Click(object sender, EventArgs e) 
     
    foreach( GridDataItem item in RadGrid1.EditItems) 
    { 
        GridEditFormItem editItem = (GridEditFormItem)item.EditFormItem; 
        if (editItem.IsInEditMode) 
        { 
            TextBox txtBox = (TextBox)editItem["OrderID"].Controls[0]; 
            Response.Write(txtBox.Text); //Edited value for OrderID column 
        } 
    } 

Thanks,
Shinu.
0
Curtis
Top achievements
Rank 1
answered on 05 Jun 2009, 03:37 PM

You can also get the values in the UpdateCommand event handler by using the following code...

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)  
    {  
        GridEditableItem editedItem = e.Item as GridEditableItem;  
 
        // get the edited values  
        Hashtable newValues = new Hashtable();  
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); 
}

 


newValues will contain the key/value pairs for the items in the editform.

You can also do the same thing in the InsertCommand but there are a couple of slight differences...

    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)  
    {  
        GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem;  
 
        // get the edited values  
        Hashtable newValues = new Hashtable();  
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, insertedItem);  

 

 Be sure to check all values for NULL because if the user didn't enter a value it will be a NULL.

 

 

Tags
Grid
Asked by
FADI
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Curtis
Top achievements
Rank 1
Share this question
or