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

Issues with RadGrid and ItemCommand

1 Answer 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 2
Nathan asked on 21 Nov 2011, 11:41 PM
Hello,

I'm using a RadGrid that is bound to a list of objects which gets set on page load (not postback). 
        RadGrid1.DataSource = myList;  
        RadGrid1.DataBind();

I've added columns that cause post backs such as imagebuttons and regular telerik button controls. When I click one of these buttons, the application throws an error in "RadGrid1_ItemCreated". The error occurs when attempting to access the grid data item and cast as my business object (Schedule). It seems the grid is no longer bound to my datasource since I'm no longer able to access this.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
if (e.Item is GridDataItem) {
  Schedule tempSchedule = (Schedule)e.Item.DataItem;

I thought it may need to be reloaded on page load, but when I put a break point on page load it doesn't hit. When clicking a button in the grid it seems to go straight to "RadGrid1_ItemCreated". Could you please give me some suggestions for correcting this issue? Do I need to cache my business object list "myList"? 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Nov 2011, 06:23 AM
Hello,

Please try with code snippet.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem) {
  Schedule tempSchedule = (Schedule)e.Item.DataItem;
}
}

Note :

ItemCreated

Occurs when an item is created in a Telerik RadGrid control.

DataBoundOccurs after the server control binds to a data source. so you can able to access item in here

http://www.telerik.com/help/aspnet-ajax/events_t_telerik_web_ui_radgrid.html

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Nathan
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or