DropDownList控件数据绑定
DropDownList控件的绑定Dictionary<int, string>
DropDownList控件的绑定DataTable
1、绑定Dictionary<int, string>
DropDownList控件的绑定DataTable
1、绑定Dictionary<int, string>
1Dictionary<int, string> temp = DBConfig.GetDataAdmin(fileName);
2this.ddlDicItem.DataSource = temp;
3this.ddlDicItem.DataTextField = "Value";
4this.ddlDicItem.DataValueField = "Key";
5this.ddlDicItem.DataBind();
2、绑定DataTable2this.ddlDicItem.DataSource = temp;
3this.ddlDicItem.DataTextField = "Value";
4this.ddlDicItem.DataValueField = "Key";
5this.ddlDicItem.DataBind();
1this.ddlAllDics.DataSource = DBConfig.Dictionary;
2this.ddlAllDics.DataTextField = DBConfig.Dictionary.Columns[1].ToString();
3this.ddlAllDics.DataValueField = DBConfig.Dictionary.Columns[0].ToString();
4this.ddlAllDics.DataBind();
特别是绑定Dictionary<int, string> ,开发中写成了2this.ddlAllDics.DataTextField = DBConfig.Dictionary.Columns[1].ToString();
3this.ddlAllDics.DataValueField = DBConfig.Dictionary.Columns[0].ToString();
4this.ddlAllDics.DataBind();
this.ddlDicItem.DataTextField = temp.Values.ToString();
这个怎么会不出错呢?失败...