Search code examples
c#asp.netdata-bindingitemtemplatebinding-expressions

Binding to a dictionary in an itemtemplate


I have a List< Dictionary< string, string>>. In the ItemTemplate of my GridView I would like to bind to the values in the dictionary based on their keys.

<ItemTemplate>
    <tr class="gridRow">
        <table width="100%">
            <tr><td><%# Eval("Lastname") %>, <%# Eval("Firstname") %> </td></tr>
            <tr><td><%# Eval("Address") %></td><td><%# Eval("Zipcode") %></td><td><%# Eval("City") %></td></tr>
        </table>
    </tr>
</ItemTemplate>

Is there anyway to do this without using code behind? I want to only have to change the ItemTemplate when new keys in the dictionary are added.


Solution

  • <%# ((Dictionary<string, string>)(Container.DataItem))["FirstName"] %>