大家好,欢迎来到IT知识分享网。
如何使用DropDownList 控件绑定数据呢,今天我们来介绍一下比较常用的一种方法——前后台结合方式:
首先,我们需要拉一个DropDownList 控件:
然后,通过控件配置SqlDataSource数据源,选择合适的数据表:
接着,设置DataTextField(数据源中提供项文本的字段)和DataValueField(数据源中提供项值的字段)属性:
前台显示如下:
配置完之后,一定不要忘记删除 DataSourceID 属性和生成的 SqlDataSource 控件:
如果需要添加额外项,比如说默认显示 “全部” 则操作如下:
选择编辑项——添加:
切记,添加之后不要忘了设置 AppendDataBoundItems 属性哦(不设置的话所添加的额外项是不显示的):
最后,在后台绑定数据源就可以了:
//绑定数据源
DropDownList1.DataSource = ProTypeManage.Select();
//执行数据绑定
DropDownList1.DataBind();
今天的分享就到此结束了,有不懂的地方可以在下方评论区留言哦。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/26591.html
![DropDownList 绑定数据[通俗易懂]插图 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/a3c383da4b5d44b4ba5aa7d64353e323.jpg)
![DropDownList 绑定数据[通俗易懂]插图1 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/aa8f33ff36324f498a8168ad9c2f8d59.jpg)
![DropDownList 绑定数据[通俗易懂]插图2 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/7e5aa56586d144fe99a64bc47954fb59.jpg)
![DropDownList 绑定数据[通俗易懂]插图3 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/924685f410e44ff2a2dcdd3d147090c8.jpg)
![DropDownList 绑定数据[通俗易懂]插图4 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/8dfcdf0aaf734156825e24a0576fe560.jpg)
![DropDownList 绑定数据[通俗易懂]插图5 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/ac9fa8a30b9e4dc882fd08e7c3355c86.jpg)
![DropDownList 绑定数据[通俗易懂]插图6 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/166cea795efe4e7bb7f4286ea5efd7fb.jpg)
![DropDownList 绑定数据[通俗易懂]插图7 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/643be199bbda423d8ced9dfca77a9d3b.jpg)
![DropDownList 绑定数据[通俗易懂]插图8 DropDownList 绑定数据[通俗易懂]](https://img.mushiming.top/app/yundeesoft_com/112533aadb754d82a4260be335055448.jpg)