如何将哈希表绑定到gridview

时间:2011-09-29 06:23:56

标签: c# asp.net gridview hashtable

我有一个哈希表,其中包含以下值集

int    ID    1
string Name  ram
list   date  2/3/2011
             5/3/2011

代码:

           <asp:TemplateField HeaderText="ID">
            <ItemStyle Width="200px"> </ItemStyle>
            <ItemTemplate>                
                <asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>                                     
            </ItemTemplate>
           </asp:TemplateField>

 its throws error in bind statement    

2 个答案:

答案 0 :(得分:1)

您需要添加RepeatorGridViewDatalist控件来绑定list ItemTemplate GridView内的{{1}}(日期)

答案 1 :(得分:0)

哈希表有keysvalues,因此您无法使用键名绑定网格(正如您所做),因为键名不是哈希表的属性。如果有的话,您可以将列绑定到KeyValue;但是,您的数据具有List个事物(日期),并且Gridview将不知道如何将此列表绑定到一个列。正如AVD所建议的那样,你需要有一个项目模板,如果你想将这样的数据结构绑定到网格视图中,你需要有另一个gridview。

相关问题