【问题标题】:Binding DataList Containing Checkboxes to a Dictionary将包含复选框的 DataList 绑定到字典
【发布时间】:2008-10-29 19:49:41
【问题描述】:

我有一个像这样的 DataList:

<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>

我将它绑定到字典:

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

目前,字典中的键和值都设置为每个复选框的文本。我希望他们字典的键是文本属性,字典的值是工具提示。我该怎么办?谢谢。

【问题讨论】:

    标签: c# asp.net .net-3.5


    【解决方案1】:

    您可以绑定到 DataItem 上的属性,在本例中为 KeyValuePair,具有 Key 和 Value 属性。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2012-09-10
      • 2013-09-04
      • 2016-08-28
      • 1970-01-01
      • 2017-05-06
      相关资源
      最近更新 更多