repeater绑定数组、哈希表、字典
datasource为 ArrayList/HashTable,Dictionary时,范例

Default7.aspx 前台页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>




http://hi.baidu.com/handboy




绑定数组






  • <%#Container.DataItem %>




绑定Hashtable






  • Key:<%#Eval("key") %>,Value:<%#Eval("value") %>










Default7.cs 后台页面:

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();//绑定数组
BindHashtable();//绑定哈希表,绑定Dictionary<>跟哈希表一样           
}

}

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(11,"hash11111111111");
hash.Add(22,"hash22222222222");
hash.Add(33,"hash33333333333");
hash.Add(44,"hash44444444444");

repHash.DataSource = hash;
repHash.DataBind();
}

}