Customer cutomer = (Customer) (record as DataRecord).Data;
cutomer.HasOrders = true;
I am casting record as a Customer. What if I don't know that my RadGrid is bound to Customer objects? Is there a way to tell what type of objects are bound to my radgrid and then cast out each record in order to get access to the properties?
You could call the GetType() method on the Data property to determine the type of object stored in it. However from there I think your looking at a switch block or the like to do your individual casts and operations on the object.
answered on 15 Dec 2008, 09:32 AM
As christopher suggested the easiest way to do that is to use the GetType method on the Data property to get the type of your data record. After that can use if statements to determine which kind of object you are dealing with. The code will look something like that:
Type dataType = dataRecord.Data.GetType();
if (dataType == typeof(Customer))
// Customers pecific code
if (dataType == typeof(Order))
// Order specific code
If you are a fan of switch statements you won't be able to use them in this scenario since you need to have an integral type (string, int, etc) and the Type object does not fall into this category.
I hope this helps.
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.