DropDownList绑定数据源,获取值
2011-06-23 18:39
190 查看
DropDownList绑定数据源,获取值
DropDownList
1. 绑定数据
private void Initialization()
{
this.dropSpecialty.DataSource = sbn.Selete("select [id], specialtyname from specialty");
this.dropSpecialty.DataTextField = "specialtyname";
this.dropSpecialty.DataValueField = "ID";
this.dropSpecialty.DataBind();
this.dropSpecialty.Items.Insert(0, new ListItem("--请选择--", "-1"));
}
这里绑定专业表,在DropDownList中显示专业的名称,但是由于存放到班级表class中是specialtID,所以同时使用了DropDownList的DataTextField属性:显示专业名称
DataValueField属性:对应的专业编号
2. 当在列表中点击编辑后,跳转到更新页面,在DropDownList中显示该班级所在的专业
此时,应使用DropDownList的SeleteValue属性,
this.dropSpecialty.SelectedValue = cdt.SpecialtyID.ToString();
与class数据表中SpecialtyID对应,DropDownList会根据Value —> DataValueField -> DataTextField -> DropDownList中显示专业名称
3. 当对DropDownList进行数据绑定后,要想实现获取DropDownList中值必须设置AppendDataBoundItems属性为True
DropDownList
1. 绑定数据
private void Initialization()
{
this.dropSpecialty.DataSource = sbn.Selete("select [id], specialtyname from specialty");
this.dropSpecialty.DataTextField = "specialtyname";
this.dropSpecialty.DataValueField = "ID";
this.dropSpecialty.DataBind();
this.dropSpecialty.Items.Insert(0, new ListItem("--请选择--", "-1"));
}
这里绑定专业表,在DropDownList中显示专业的名称,但是由于存放到班级表class中是specialtID,所以同时使用了DropDownList的DataTextField属性:显示专业名称
DataValueField属性:对应的专业编号
2. 当在列表中点击编辑后,跳转到更新页面,在DropDownList中显示该班级所在的专业
此时,应使用DropDownList的SeleteValue属性,
this.dropSpecialty.SelectedValue = cdt.SpecialtyID.ToString();
与class数据表中SpecialtyID对应,DropDownList会根据Value —> DataValueField -> DataTextField -> DropDownList中显示专业名称
3. 当对DropDownList进行数据绑定后,要想实现获取DropDownList中值必须设置AppendDataBoundItems属性为True
相关文章推荐
- DropDownList绑定数据源,获取值
- ASP.NET dropdownlist绑定数据源两种方法
- 获取数据源绑定控件主键
- asp.net DropDownList绑定树形数据源
- Sqldatareader 绑定后如何在ItemDataBound事件获取数据源
- Asp.net Webform 数据源绑定控件的扩展(懒人的办法):DropDownList
- Repeater中的下拉列表DropDownList绑定数据源
- DropDownList动态绑定数据源
- DataSet绑定Hashtable为DropDownList提供数据源
- asp.net: DropDownList绑定数据源及选中某个值的公用方法及例子
- 在Datagridview中双事件获取行号时数据源重新绑定后
- Dropdownlist绑定数据源之后,如何设置期中一个项目为已选项
- DropDownList绑定数据源的方法
- DropdownList控件动态绑定数据源两…
- 如何使用DropDownList进行数据绑定并获取值
- GridView绑定时通过RowDataBound事件获取数据源列值
- 让Dropdownlist既有静态项又有动态项或者既能有编辑项又能绑定数据源
- Asp.net 获取服务器文件列表并绑定到DropDownList
- NPOI动态获取数据源绑定Gridview显示
- GridView绑定时通过RowDataBound事件获取数据源列值