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

casting griddataitem to custom object or class

2 Answers 713 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 26 Mar 2013, 08:22 PM
Hi,

Using Rad controls for asp.net ajax 2013 Q1 with visual studio 2012 ultimate c#.
We have some global code that is used by all the grids in all the pages. In itemDataBound event of RadGrid, I need to get row data and pass it on to global code. Currently, with the grid we are using:
  
    customClass rowData = (customClass) e.data;

Is it possible to cast itemdata to custom object. If yes, please let me know how and example link.

Thanks,
Prathiba.

2 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 29 Mar 2013, 11:08 AM
Hi,

In order to achieve your goal you could use the following approach:

Object dataItem = null;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        dataItem = e.Item.DataItem;
    }
}

Thus the dataItem will be available to all the methods in this class.

Regards,
Andrey
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.
0
Prathibarani
Top achievements
Rank 1
answered on 01 Apr 2013, 03:26 PM
Thank you. It worked.

Prathiba
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Prathibarani
Top achievements
Rank 1
Share this question
or