加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 强类型的数据绑定和泛型?

发布时间:2020-12-15 17:35:58 所属栏目:百科 来源:网络整理
导读:假设我想使用新的ASP.NET 4.5强类型数据绑定将通用类型(这里:Dictionary string,string)绑定到Repeater. 然后我必须放下KeyValuePair string,string作为中继器的ItemType属性. asp:Repeater id="rpCategories" runat="server" ItemType="System.Collections
假设我想使用新的ASP.NET 4.5强类型数据绑定将通用类型(这里:Dictionary< string,string>)绑定到Repeater.

然后我必须放下KeyValuePair< string,string>作为中继器的ItemType属性.

<asp:Repeater id="rpCategories" runat="server" ItemType="System.Collections.Generic.KeyValuePair<string,string>">

这里有一个明显的问题:我不能使用<或>在ItemType文本内! 怎么会这样呢?使用泛型可能以某种方式使用新的数据绑定模型?

解决方法

这对我有用:

代码背后

protected void Page_Load(object sender,EventArgs e)
        {
           rpCategories.DataSource = new Dictionary<string,string>()
            {
                {"1","item"},{"2",{"3",};
        rpCategories.DataBind();
        }

标记

<asp:Repeater ID="rpCategories" runat="server" ItemType="System.Collections.Generic.KeyValuePair`2[System.String,System.String]">
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%# Item.Key %>'></asp:Label>
        </ItemTemplate>
    </asp:Repeater>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读