前台下拉框控件
前台拉一个名字为DropDownList1的下拉框
注意:如果要触发下拉框事件要把DropDownList的AutoPostBack属性设置为True
后台事件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//用来给com数据源
ArrayList list = new ArrayList();
//key value
Hashtable tab = new Hashtable();
tab.Add("0001", "未审核");
tab.Add("0002", "已审核");
tab.Add("0003", "未结算");
tab.Add("0004", "已结算");
//将hashtable作为源给list
foreach (System.Collections.DictionaryEntry ent in tab)
{
list.Add(ent);
}
//将list作为数据源给下拉框
DropDownList1.DataSource = list;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "Value";
DataBind();
}
}
//下拉框改变事件
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//SelectedValue 当前选中的下拉框的值
string a = DropDownList1.SelectedValue.ToString();
MessageBox.Show(this, a);
}