更新时间:2022-10-21 09:18:43
很简单,你需要将所有值附加到sql查询中的单个列中将该列绑定到dropdownlist的value字段。然后在split功能的帮助下,您可以获得所有的值...
示例 -
选择名称+' - '+ branch +' - '+ rollno作为yourtablename的值
这里你可以将值列绑定到下拉列表值字段。
on the C#页面使用如下代码var value = ddl.SelectedValue.Split(' - ')。ToList();
字符串 name = lowerUpperval [ 0 ];
字符串 branch = lowerUpperval [ 1 ];
字符串 rollno = lowerUpperval [ 2 ];
享受
Happy Codding !!!
嘿,
小心这个
http://www.c-sharpcorner.com/forums/thread/211808/how-to-bind- multiple-values-from-database-dropdownlist.aspx [ ^ ]
http://***.com/questions/6455568/how-to-bind-two -cloumns-values-in-dropdown-with-separate-comma [ ^ ]
谢谢
ketan
首先从数据库中获取数据表...
然后,如果你的数据库包含两列,一个名为Text,另一个名为Value
你只需说
yourDropDownList.DataSource = yourDataTable;
yourDropDownList.DataTextField =Text;
yourDropDownList.DataValueField =Value;
yourDropDownList .DataBind();
how to bind multiple value in dropdownlist from the database
It,s very simple you need to append all that values to a single column in sql query and bind that column to value field of dropdownlist.Then by the help of split fuction you can get all the value...
Example-
select name + '-' + branch + '-' + rollno as value from yourtablename
here you can bind the value column to the dropdownlist value field.
on the C# page use code as as belowvar value= ddl.SelectedValue.Split('-').ToList(); String name=lowerUpperval[0]; String branch= lowerUpperval[1]; String rollno=lowerUpperval[2];
Enjoy
Happy Codding!!!
hey,
take a loook this
http://www.c-sharpcorner.com/forums/thread/211808/how-to-bind-multiple-values-from-database-dropdownlist.aspx[^]
http://***.com/questions/6455568/how-to-bind-two-cloumns-values-in-dropdown-with-separate-comma[^]
thanks
ketan
First get a datatable from the database...
Then if your database contains two columns, one named "Text" and one named "Value"
you just say
yourDropDownList.DataSource = yourDataTable;
yourDropDownList.DataTextField = "Text";
yourDropDownList.DataValueField = "Value";
yourDropDownList.DataBind();