dropdownlist清空

时间:2024-06-13 19:32:02编辑:阿奇

asp.net中怎么清除dropdownlist中的项目

页面代码






aaa
bbb
ccc
ddd






cs 文件代码
protected void Button1_Click(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
}
protected void Button2_Click(object sender, EventArgs e)
{
DropDownList1.Items.Remove("bbb");
}


asp.net2.0 中的DropDownList控件如何重置?

DropDownList 有两个属性,一个属性是DataTextField,一个是DataValueField
分别对应键和值
如果说想要在DropDownList中显示数据库中某一个表中的内容
举个例子,表结构如下
ID,Name
1 技术部
2 财务部
在代码中可以这样写:
DropDownList.DataSource=表;//表是从数据库中读取
DropDownList.DataTextField="Name"; //显示的是部门
DropDownList.DataValueField="ID"; //记录的是部门ID
DropDownList.DataBind();

如果要显示财务部,只需要在绑定所有项完成之后写上
DropDownList.SelectedValue="2"; //即可显示财务部


上一篇:槐茂酱菜

下一篇:远行客户外