views:

762

answers:

1

Hi.

I have a DataList like so:

<asp:DataList ID="dlMyList" runat="server" RepeatColumns="5" 
        RepeatDirection="Horizontal" CellSpacing="5" >
    <ItemTemplate>
        <asp:CheckBox ID="cbMyBox" Runat="server" Text='<%# Container.DataItem%>' ToolTip=''></asp:CheckBox>
    </ItemTemplate>
</asp:DataList>

I'm binding this to a Dictionary:

Dictionary<string, string> l_CheckboxData = GetCheckboxData();
this.dlMyList.DataSource = l_CheckboxData;
this.dlMyList.DataBind();

At the moment, both the key and the value from the dictionary are set as the Text for each checkbox. I'd like to have it such that they Dictionary's key is the Text property and the Dictionary's value is the ToolTip. How would I go about this? Thanks.

+1  A: 

You can bind to the properties on the DataItem, which, in this case, is a KeyValuePair, having Key and Value properties.

<asp:CheckBox ID="cbMyBox" Runat="server" Text='<%# Eval("Key")%>' ToolTip='<%#Eval("Value")'></asp:CheckBox>
bdukes