怎么把Dictionary<key,value>绑定到下拉菜单ddl谢谢

解决方案 »

  1.   

    DictionaryEntry de = new DictionaryEntry();
            de.Key = "111";
            de.Value = "111";
            DropDownList ddl = new DropDownList();
            ddl.Items.Add(new ListItem(de.Value.ToString(), de.Key.ToString()));
      

  2.   

    貌似不能直接绑定,你可以循环Dictionary 键值,然后加到table或者加进类数组也可
      

  3.   

    参考:  protected void Button1_Click(object sender, EventArgs e)
        {
            DropDownList1.DataTextField = "value";
            DropDownList1.DataValueField = "key";
            DropDownList1.DataSource = GetTypeList();
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, new ListItem("请选择"));
        }    protected Dictionary<int, string> GetTypeList()
        {
            Dictionary<int, string> list = new Dictionary<int, string>();
            list.Add(1, "one");
            list.Add(2, "two");
            list.Add(3, "three");
            list.Add(4, "four");
            return list;
        }