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

[Solved] Problem item type with GridCalculatedColumn

4 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
VANDENBERGHE
Top achievements
Rank 1
VANDENBERGHE asked on 02 Jun 2008, 09:41 AM
Hi everyone,

I found an issue with the RadGrid Component. If I add a GridCalculatedColumn to the RadGrid, I can't write the sample of code you could find below anymore. In fact, e.Item.DataItem belongs to type DynamicCalss1 (see in debugger) but I can't use it for accessing to the methods of the Item.

protected void gridViewCtrl_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
{  
     if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item ||  
          e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)  
     {  
          ProductDataContract prod = e.Item.DataItem as ProductDataContract;  
          prod.DoSomething();  
     }  

The only workaround I found is to not use this type of column, but it is really unconfortable to not use it.

I'm pretty sure there is another solution, so I will be very happy if you could help me.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jun 2008, 10:34 AM
Hi,

Try accessing the GridCalculatedColumn's cell value using the ColumnUniqueName property as shown below.

ASPX:
<telerik:GridCalculatedColumn UniqueName="CalCol" HeaderText="CalCol" DataFields=" SupplierID, ProductID"  Expression="{0}*{1}" ></telerik:GridCalculatedColumn> 
 


CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            string strtxt = item["CalCol"].Text.ToString();  
              
        }  
    } 


Thanks
Princy.
0
VANDENBERGHE
Top achievements
Rank 1
answered on 02 Jun 2008, 11:07 AM

Thanks for your quick answer,

My problem is not accessing to the column, but really retrieve the DataItem in is real type. I want to execute its own method. I don't understand why the DataItem type is modified at run time and how I can cast it to retrieve the good one.

The cast works well with all other column type. I have just found this issue when I added a GridCalculatedColumn to the RadGrid.

Regards.

0
VANDENBERGHE
Top achievements
Rank 1
answered on 05 Jun 2008, 07:42 AM
Perhaps you can just explain me why item type is changed ?
0
Accepted
Rosen
Telerik team
answered on 05 Jun 2008, 11:14 AM
Hello VANDENBERGHE,

You probably know that RadGrid for ASP.NET AJAX use internally LINQ to objects. Therefore, when calculated column is used, a dynamic class is necessary to be used as the property to store the calculated column values is needed.
To avoid that if you prefer, you can disable the internal LINQ functionality by setting the EnableLinqExpressions property of the grid to false.

Best regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
VANDENBERGHE
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
VANDENBERGHE
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or