The original Published time: 2009-11-19--from my Baidu article [imported by moving tools]
repeater binding arrays, hash tables, dictionaries
DataSource for
Arraylist/hashtable,dictionary, example
Default7.aspx Front Page:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default7.aspx.cs" inherits= "Default7"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>http://hi.baidu.com/handboy</title>
<body>
<form id= "Form1" runat= "Server" >
<div>
Binding arrays
<ul>
<asp:repeater id= "Reparray" runat= "Server" >
<ItemTemplate>
<li>
<% #Container. DataItem%>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Binding Hashtable
<ul>
<asp:repeater id= "Rephash" runat= "Server" >
<ItemTemplate>
<li>
key:<% #Eval ("key")%>,value:<% #Eval ("Value")%>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</form>
</body>
Default7.cs background page:
Using System;
Using System.Web.UI.WebControls;
Using System.Collections;
public partial class Default7:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Bindarray ();//bound array
Bindhashtable ();//bind hash table, bind dictionary<> as hash table
}
}
protected void Bindarray ()
{
ArrayList arr = new ArrayList ();
Arr. ADD ("arr11111111111");
Arr. ADD ("arr22222222222");
Arr. ADD ("arr33333333333");
Arr. ADD ("arr44444444444");
Reparray.datasource = arr;
Reparray.databind ();
}
protected void bindhashtable ()
{
Hashtable hash = new Hashtable ();
Hash. ADD (One, "hash11111111111");
Hash. ADD ("hash22222222222");
Hash. ADD ("hash33333333333");
Hash. ADD ("hash44444444444");
Rephash.datasource = hash;
Rephash.databind ();
}
}
Repeater binding array, hash table, dictionary arraylist/hashtable,dictionary to DataSource