动态绑定下拉框
Posted 都一样
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态绑定下拉框相关的知识,希望对你有一定的参考价值。
//动态绑定下拉框
string sql = "select id ,name form B ";
DataTable dt = DBHelper.GetDataTable(sql);
//绑定数据源
this.comboBox1.DataSource = dt;
//绑定要显示的文本的字段
this.comboBox1.DisplayMember = "name";
//绑定真实的值value
this.comboBox1.valueMember = "id";
//弹出下拉框的值或文本
string name = this.comboBox1.Text;
string id = this.comboBox1.SelectdValue.ToString();
MessageBox.Show(name);
以上是关于动态绑定下拉框的主要内容,如果未能解决你的问题,请参考以下文章
bootstrap select下拉框模糊搜索和动态绑定数据解决方法