如何从数据库中的dropdownlist中绑定多个值 [英] how to bind multiple value in dropdownlist from the database

查看:115
本文介绍了如何从数据库中的dropdownlist中绑定多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在数据库中的dropdownlist中绑定多个值

解决方案

很简单,你需要将所有值附加到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://stackoverflow.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 below

var 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://stackoverflow.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();


这篇关于如何从数据库中的dropdownlist中绑定多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆