System.Collections.Hashtable ht=new Hashtable();
ht.add(4,5,2,1);
Session["buy"]=ht;然后我要绑定到DataGrid请问一下字段要怎么写呢

解决方案 »

  1.   

    dataGrid1.DataSource = ht;
    dataGrid1.DataBind();
      

  2.   

    DataGrid1.DataSource = (Hashtable)Session["buy"];
    CataGrid1.DataBind();
      

  3.   

    使用模板列:
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 106; LEFT: 256px; POSITION: absolute; TOP: 16px" runat="server" autogeneratecolumns="False">
        <columns>
            <asp:TemplateColumn>
                <itemtemplate>
                        <label id="lblText"><%# DataBinder.Eval(Container, "DataItem") %></label>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>绑定:
    DataGrid1.DataSource = ht.Values;
    //DataGrid1.DataSource = ht.Keys;
    DataGrid1.DataBind();不过呢,最好还是把ht转换为一个DataTable,然后再绑定DataTable.