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

Accessing e.Item.DataItem from OnClick event of Button which is placed in ItemTemplate

1 Answer 295 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GrZeCh
Top achievements
Rank 2
GrZeCh asked on 18 Dec 2008, 06:57 PM
Hello!

Sorry for long title :). I have a button placed instide MasterTableView \ ItemTemplate which has attached server-side OnClick event. Normally in RadGrid event OnItemDataBound I can access databinded item for this row by using this:

MyClass dataItem = (MyClass )e.Item.DataItem; 

but how can I access DataItem in OnClick event of Button which is inside ItemTemplate? If accessing is not possible then how can I pass this DataItem to this Button.

Thanks

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 19 Dec 2008, 07:05 AM
Hello GrZeCh,

Generally e.Item.DataItem is available only during data-binding exactly in the same way as in MS DataGrid and GridView. After post-back you can get the data key value for desired item and filed declared in DataKeyNames. Here is an example for Button click event handler:

GridDataItem item  = (GridDataItem)((Button)sender).NamingContainer;
object value = item.GetDataKeyValue("YourDataKeyName");
// here you can find actual item in your collection of objects using this value.


Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
GrZeCh
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Share this question
or