我正在尝试填充 <li>
带有转发器的项目,将其绑定(bind)到 Dictionary 对象。我有一本名为 cart 的字典,它具有标准的 Key、Value 属性。
我收到一个运行时错误:
`System.InvalidCastException: Specified cast is not valid.`
我使用了这段代码:
<ItemTemplate>
<li id="<%# ((KeyValuePair<string,string>)Container.DataItem).Key %>_i" >
<%# ((KeyValuePair<string,string>)Container.DataItem).Key %> <%# ((KeyValuePair<string,string>)Container.DataItem).Value %>
</li></ItemTemplate>
这里有什么问题吗?
最佳答案
当绑定(bind)到 Dictionary<string, string>
时,您的 ItemTemplate 对我有用.因此,我建议检查 Repeater 是否真的绑定(bind)到 Dictionary<string, string>
。 .
如果不是,异常是有意义的,可以通过修复数据绑定(bind)代码(或更改 ItemTemplate 中使用的类型,使其与绑定(bind)到 Repeater 的数据相匹配)来解决。
关于c# - 将字典绑定(bind)到转发器 asp.net 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22060951/