Can I use a specific dictionary key as a DataTextField if that dictionary is a property of my datasource?

184 views Asked by At

Rough class schema:

public class Entity
{
    public Guid ID;
    public Dictionary<String, object> Attributes;
}

Attributes has the following keys: listname (string), membercount(integer), type (boolean).

I have a Telerik RadComboBox which is databound through code-behind to a List and has an ItemTemplate:

<telerik:RadComboBox runat="server" ID="CboLists" DataValueField="Id">
    <ItemTemplate>
        <table>
            <tr>
                <td>
                   <b><%# DataBinder.Eval(Container.DataItem, "Attributes['listname']") %></b> (<%# ViewHelper.GetBooleanValue("list", "type",(bool)((Entity)Container.DataItem).Attributes["type"]) %>)
                </td>
            </tr>
            <tr>
                <td>
                    <%# DataBinder.Eval(Container.DataItem, "Attributes['membercount']") %> Leden
                </td>
            </tr>
        </table>
    </ItemTemplate>
</telerik:RadComboBox>

I want to show the value of the Attribute with key listname in the combobox as the DataTextField, but I cannot figure out how to do this. I've checked on here and everything I can find on using dictionaries in a combobox involves using a dictionary as the datasource. I would think it's possible, because it works in the ItemTemplate, and I can get it to work in a RadGrid on the DataField property using Attributes[listname], but when I try that construct, it doesn't work.

How can i get this to work?

0

There are 0 answers