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

Possible to bind a column to DataItem Attribute?

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Coy
Top achievements
Rank 1
Coy asked on 01 Feb 2011, 05:29 PM
Hi,

I'm binding my grid to a collection of objects, unfortunately, the object only contains an id of another object that I want to display the Display Value for.  So rather than make a service tier change, I'm handling the retrieval within the UI.

My question is, do DataItem Attributes have a DataField property value so I can bind to them?

I'm using NeedsDatasource to bind and then explicitly using telerik:GridBoundColumn to handle which columns are displayed.

I'm adding my Attributes in the code behind in ItemDataBound, like this:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        Object obj1= (Object)e.Item.DataItem;
        e.Item.Attributes.Add("Attribute1", DataSet.Find(p => p.Code == obj1.Code).DisplayValue);
    }
}


Is there a way to bind a column to the Attribute named "Attribute1"?

Thanks!

Coy

1 Answer, 1 is accepted

Sort by
0
Coy
Top achievements
Rank 1
answered on 01 Feb 2011, 08:39 PM
I've figured out a work around so an answer is unneeded at this time.

Instead of trying to bind to the attributes collection, which I don't believe is possible at the moment, I simply use a GridTemplateColumn with a Label inside it.

On ItemDataBound, I access the label and put the value into the text property of the label.

This works well for what I need to accomplish.

Thanks!

Coy
Tags
Grid
Asked by
Coy
Top achievements
Rank 1
Answers by
Coy
Top achievements
Rank 1
Share this question
or