【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);
}
前台拉一个名字为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);
}
相关文章推荐
- DevExpress Asp.net(8) ASPxTreeList的基本使用之二
- Wap页面使用asp.net中移动控件List分页
- DevExpress Asp.net(7) ASPxTreeList的基本使用之一
- 在ASP.NET MVC中使用“RadioButtonList”和“CheckBoxList”
- ASP.NET MVC 3 CheckBoxList 的使用
- 在ASP.NET MVC中使用“RadioButtonList”和“CheckBoxList”
- ASP.NET MVC 3 CheckBoxList 的使用
- 关于ASP.NET下,JQuery+AJAX使用JSON返回对象集合List数据的总结
- DevExpress Asp.net(7) ASPxTreeList的基本使用之一
- [C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- ASP.NET List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- Asp.net MVC、Extjs(运用Linq to SQL和List泛型)批量更新、删除、打印(使用CKEditor)、导出Excel
- [C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- asp.net中List的使用方法
- 在Asp.Net MVC中使用ModelBinding构造Array、List、Collection以及Dictionary
- Wap页面使用asp.net中移动控件List分页
- AjaxControltoolkit学习笔记—PagingBulletedList使用详解 (asp.net C#)
- DevExpress Asp.net ASPxTreeList的基本使用之一
- 【转载】[C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- ASP.NET MVC 3 CheckBoxList 的使用