Mat*_*tin 2 c# asp.net repeater sorteddictionary
我认为我很聪明地从内存密集型DataView切换到SortedDictionary作为内存高效的可排序数据结构.现在我不知道如何从<%#或Eval()表达式中获取数据源的键和值.
SortedDictionary<int, string> data = RetrieveNames();
rCurrentTeam.DataSource = data;
rCurrentTeam.DataBind();
<asp:Repeater ID="rNames" runat="server">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("what?") %>' />
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
使用以下两个选项之一:
<%# Eval("Key") %>
<!-- or -->
<%# Eval("Value") %>
Run Code Online (Sandbox Code Playgroud)
取决于您是否需要键或字典中的值.
如果您考虑数据绑定的工作原理,这是有道理的.数据绑定是一个过程,通过该过程,控件获取可枚举的序列,迭代该序列,并使用反射根据项目公开的属性从序列中的每个项目中提取值.
由于SortedDictionary<TKey,TValue>实现了IEnumerable<KeyValuePair<TKey, TValue>>接口,您知道转发器将枚举一系列KeyValuePair<TKey, TValue>对象,依次绑定到每个对象.
如果您查看KeyValuePair<TKey,TValue>该类公开的属性,您将只看到两个:Key和Value.由于它们是公共属性Eval,因此控件将能够提取它们封装的值.
| 归档时间: |
|
| 查看次数: |
2144 次 |
| 最近记录: |