将Hashtable绑定到RadioButtonList Web控件


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();
  }
}
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3