【发布时间】:2011-10-17 18:05:07
【问题描述】:
我使用 asp.net 4 c#。
我有一个网格视图,位于标签内。我想知道如何将第一个标签的 Text 属性绑定到字典 KEY 并将第二个标签绑定到字典 VALUE,而不使用 gridview 事件 DataBound 或类似的。
请举个例子,谢谢
<asp:GridView ID="uxContentByYearMonths" runat="server">
<Columns>
<asp:TemplateField HeaderText="Month">
<ItemTemplate>
<asp:Label ID="uxMonth" runat="server" Text='<%# Bind("Key") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Content">
<ItemTemplate>
<asp:Label ID="uxCount" runat="server" Text='<%# Bind("Value") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
// DataSource
Dictionary<int, int> result = new Dictionary<int, int>();
【问题讨论】:
-
考虑为您的 GridView 使用 ObjectDataSource。网络上有很多关于它是什么以及如何使用它的示例。
-
感谢卢卡萨斯的建议