假设我想使用新的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>
原文地址:https://www.jb51.cc/csharp/96408.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。