Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to bind multiple value in dropdownlist from the database
Posted
Comments
Marvin Ma 27-Aug-13 2:50am    
Did you mean a ComboBox?

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
C#
var value= ddl.SelectedValue.Split('-').ToList();
             String  name=lowerUpperval[0];
             String  branch= lowerUpperval[1];
             String  rollno=lowerUpperval[2];


Enjoy
Happy Codding!!!
 
Share this answer
 
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900