views:

184

answers:

2

Not sure if the title of this question makes sense, but here's my problem:

I have a telerik grid bound to a Linq data object, however, I limit the fields returned:

<IQueryable>filter = data.Select(x => new {x.ID, x.Name, x.Age});

I would like to access these fields in the ItemCreated method of the grid:

protected void rgPeople_ItemCreated(object sender, GridItemEventArgs e)
{
  Telerik.Web.UI.GridDataItem item = (GridDataItem)e.Item;
  ?????? Person = (???????)e.Item.DataItem;
}

What do I declare ?????? as so that I can use:

String ID = Person.ID;
String Name = Person.Name; etc
A: 

Something like this:

protected void rgPeople_ItemCreated(object sender, GridItemEventArgs e)
{
   if(e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType =                          GridItemType.Item)
    {    
        Telerik.WebControls.GridDataItem item = e.Item;

        Label lbl as Label;

        lbl= item("ColumnName").FindControl("lblName")



    }
}

Juding by what you want to nkow how to do - perhaps you should be performing your task on the OnRowDataBinding event.

TheGeekYouNeed
Thanks, but you completely missed the point of the question.
Jack
A: 

No, I didn't miss your point. A Label is as much of an object as a GridDataItem, or your "Person" object. I understand that your point is to be spoonfed a solution, so here you go.

protected void rgPeople_ItemCreated(object sender, GridItemEventArgs e)
{   
    if (e.Item is GridDataItem)
    {
        var item = ((GridDataItem)e.Item);
        Hashtable values = new Hashtable();
        item.ExtractValues(values);
        string Name = (string)values["Name"];
        string ID = (string)values["ID"];
        string Age = (string)values["Age"];
    }
 }
TheGeekYouNeed
Or instead of the hashtable, did you try Person person = (Person)((GridDataItem)e.Item);
TheGeekYouNeed