现在的位置: 首页 > 综合 > 正文

数据绑定技术—将Hashtable绑定到RadioButtonList Web控件

2012年04月29日 ⁄ 综合 ⁄ 共 526字 ⁄ 字号 评论关闭
void Page_Load(object sender, System.EventArgs e)
{
    
if(!IsPostBack)
    
{
        
// 创建 Hashtable 对象并填充数据
        Hashtable hash = new Hashtable();
        hash.Add(
"北京""010");
        hash.Add(
"广州""020");
        hash.Add(
"上海""021");
        hash.Add(
"天津""022");
        hash.Add(
"成都""028");
        hash.Add(
"济南""0531");

        
// 进行数据绑定
        RadioButtonList1.DataSource = hash;
        RadioButtonList1.DataTextField 
= "Key";
        RadioButtonList1.DataValueField 
= "Value";
        RadioButtonList1.DataBind();
    }

}

抱歉!评论已关闭.