关键代码:
1
DropDownList1.DataTextField = "value";
2
DropDownList1.DataValueField = "key";
3
DropDownList1.DataSource = getTypeList();
4
DropDownList1.DataBind();
DropDownList1.DataTextField = "value";2
DropDownList1.DataValueField = "key";3
DropDownList1.DataSource = getTypeList();4
DropDownList1.DataBind();实例代码:
1
protected void Button1_Click(object sender, EventArgs e)2
{3
DropDownList1.DataTextField = "value";4
DropDownList1.DataValueField = "key";5
DropDownList1.DataSource = getTypeList();6
DropDownList1.DataBind();7
}8
public Dictionary<int, string> getTypeList()9
{10
Dictionary<int, string> list = new Dictionary<int, string>();11
list.Add(1, "L1用户");12
list.Add(2, "L2用户");13
list.Add(3, "赢富用户");14
list.Add(4, "股指期货用户");15
return list; 16
}17
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)18
{19
Response.Write(DropDownList1.SelectedValue.ToString());20
}