您的位置:首页 > 编程语言 > ASP

【ASP.NET】使用HashTable和List给…

2014-12-30 21:53 232 查看
前台下拉框控件

前台拉一个名字为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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: