DataList bindet Daten an eine generische Klasse (Dictionary)

 

Verwenden  des Systems;   

Verwenden von  System.Data;   

Verwenden von  System.Configuration;   

mit  System.Web;   

mit  System.Web.Security;   

mit  System.Web.UI;   

mit  System.Web.UI.WebControls;   

mit  System.Web.UI.WebControls.WebParts;   

mit  System.Web.UI.HtmlControls;   

mit  System.Collections.Generic;   

öffentliche  Teilklasse  _Default  : System.Web.UI.Page    

{   

protected void  Page_Load( Objektsender  , EventArgs e)    

  {   

  if  (!IsPostBack)   

   {   

 Dictionary< string , A> d =  new  Dictionary< string , A>();   

 d.Add( "aa"new  A( "1""xx" ));   

  d.Add( "bb"new  A( "2""yy" ));   

 d.Add( "cc"new  A( "3""zz" ));   

 

 DataList1.DataSource = d;   

DataList1.DataBind();   

 }   

}   

}   

 

öffentliche Klasse  A    

{   

 private Zeichenfolge  m_PKID;    

private Zeichenfolge  m_Type;    

 

  öffentliche Zeichenfolge  PKID    

 {   

 get  {  return  m_PKID; }   

set  { m_PKID = value; }   

}   

 

  öffentlicher String-  Typ    

 {   

  get  {  return  m_Type; }   

  set  { m_Type = value; }   

}   

 

 öffentliches  A() { }   

 

  public  A( string  pkid,  string  type)   

 {   

  this .m_PKID = pkid;   

  this .m_Type = type;   

  }   

}  

 

< asp:DataList ID = "DataList1" runat = "server" OnItemDataBound = "DataList1_ItemDataBound" >     

  < ItemTemplate >  

    < %#( (System.Collections.Generic.KeyValuePair < ​​string , A > )(Container.DataItem)).Key % >  

   < %#( ((System.Collections.Generic.KeyValuePair < ​​string , A > )(Container.DataItem)).Value as A).PKID % >  

  < %#( ((System.Collections.Generic.KeyValuePair < ​​string , A > )(Container.DataItem)).Value as A).Type % >  

  </ ItemTemplate >  

</ asp:DataList >  

Acho que você gosta

Origin blog.csdn.net/dj1232090/article/details/2776181
Recomendado
Clasificación