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

Accessing data from newly inserted row after initial ItemDataBound

2 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boyan
Top achievements
Rank 1
Boyan asked on 13 Nov 2012, 01:14 AM
Hi,

I have a RadGrid with a GridTemplateColumn whose EditItemTemplate contains a DropDownList and a label control for displaying error messages. When I insert a new item and change the selection in the drop-down list, I would like to be able to update other drop-down list controls in the other columns of the grid. When editing an item, I am able to do so inside the SelectedIndexChanged event of the drop-down list control using the following code:

editedIndex = grid.EditIndexes[0];
item = grid.EditItems[editedIndex] as GridEditableItem;

list = item.FindControl("txtBox1") as DropDownList;
list.DataSource = listValues;
list.DataBind();

When inserting an item, however, grid.EditItems.Count is 0 and I don't know how to access the newly inserted line in the grid and its controls.

Could anyone point me in the right direction?

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 13 Nov 2012, 07:11 PM
I am a little unclear about when you need to access the row being inserted
the edit item on an insert is a different type than an edit (technically, it implements different interfaces)
the actual object type(s) depend on the EditMode being employed
once the row is added and the grid refreshed it becomes just another grid item, which can be located by iterating through the grid
- is your RadAjaxManager set up properly?  if it isn't your code will have problems
0
Angel Petrov
Telerik team
answered on 15 Nov 2012, 04:24 PM
Hello Marianne,

You are right the object depends on the EditMode. Additionally in this particular case I think that Boyan can intercept the OnInsertCommand event and cast the item to GridEditableItem like in the following code snippet.
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem item = (e.Item as GridEditableItem);
       //your code logic
   }
Still it would be best if we could see the RadGrid markup so that we can give a more precise solution.

Regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Boyan
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Angel Petrov
Telerik team
Share this question
or