绑定Hashtable到DataList
实现将Hashtable数据动态绑定到DataList
后台CS代码:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Hashtable list = new Hashtable(); list.Add("阿伟", "awei"); list.Add("张三", "zs"); list.Add("李四", "ls"); this.DataList1.DataSource = list; this.DataList1.DataBind(); } }
前台页面HTML代码:
<form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333"> <HeaderTemplate> <table width="200"> <tr> <td width="100"> 中文 </td> <td> ENGLISH </td> </tr> </table> </HeaderTemplate> <ItemTemplate> <table width="200"> <tr> <td> <%# ((DictionaryEntry)Container.DataItem).Key %> </td> <td> <%# ((DictionaryEntry)Container.DataItem).Value %> </td> </tr> </table> </ItemTemplate> </asp:DataList> </div> </form>