hashtable 绑定的datagrid

cs code
         protected  System.Web.UI.WebControls.DataList datalist;
        Hashtable o 
=   new  Hashtable();
        
private   void  Page_Load( object  sender, System.EventArgs e)
        
{
            DataTable dt 
= new DataTable();
            dt.Columns.Add(
"saf");
            DataRow dr 
= dt.NewRow();
            dr[
0= "todd ha ha";
            dt.Rows.Add(dr);
            dr 
= dt.NewRow();
            dr[
0= "summy ha ha";
            dt.Rows.Add(dr);
            o.Add(
1,dt);
            o.Add(
2,dt);
            o.Add(
3,dt);
            
this.datalist.DataSource = o;
            
this.datalist.DataBind();
        }

        
private   void  datalist_ItemDataBound( object  sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        
{
            DataGrid obj 
= ((DataGrid)(e.Item.FindControl("datagridtest")));
            
//object objItem = this.datalist.DataKeys[e.Item.ItemIndex];
            System.Collections.DictionaryEntry Entity = (System.Collections.DictionaryEntry)(e.Item.DataItem);
            DataTable bb 
= ((DataTable)(Entity.Value));
            obj.DataSource    
= bb;
            obj.DataBind();        
        }
aspx code
     < asp:DataList  ID ="datalist"  Runat ="server"   DataKeyField  ="key" >
                
< ItemTemplate >
                    
< asp:Label  ID  ="labeltest"  Runat =server  text ='<%#  DataBinder.Eval(Container, "DataItem.key")% > ' >
                    
</ asp:Label >
                    
< asp:DataGrid  ID ="datagridtest"  Runat =server   ></ asp:DataGrid >
                
</ ItemTemplate >
            
</ asp:DataList >

你可能感兴趣的:(Hashtable)