public class M_DATA
{
string key;
public string Key
{
get { return key; }
set { key = value; }
}
string value;
public string Value
{
get { return this.value; }
set { this.value = value; }
}
}
protected void Page_Load(object sender, EventArgs e)
{
//Hastable構造的數據源
Hashtable m_data = new Hashtable();
for (int i = 0; i < 10; i++)
{
m_data.Add(i, "Txt" + i.ToString());
}
CheckBoxList1.DataSource = m_data;
CheckBoxList1.DataTextField = "key";
CheckBoxList1.DataValueField = "value";
CheckBoxList1.DataBind();
//類定義的構造的數據源
List<M_DATA> m_list = new List<M_DATA>();
for (int j = 0; j < 10; j++)
{
M_DATA m_c = new M_DATA();
m_c.Key = j.ToString();
m_c.Value = "TxtClass" + j.ToString();
m_list.Add(m_c);
}
RadioButtonList2.DataSource = m_list;
RadioButtonList2.DataMember = "M_DATA";
RadioButtonList2.DataTextField = "value";
RadioButtonList2.DataValueField = "key";
RadioButtonList2.DataBind();
}