Follow by Email

How to show multiple columns in the single dropdown list using sqlreader?

Here i will show you how can u bind the multiple columns ti the single dropdown list..

Add dropdown list from toolbox.
Now bind the data at the page load event of the page.

protected void Page_Load(object sender, EventArgs e)
       string connectionString = 
"Data Source=VRAKSH-VAIBHAVS;Initial Catalog=AdventureWorks;Persist Security Info=True;User ID=sa;Password=data#123";
       SqlConnection con = new SqlConnection(connectionString);
       SqlCommand cmd = new SqlCommand 
("select City + ' ' + PostalCode as PCity from Person.Address", con);
       SqlDataReader rd;
       rd = cmd.ExecuteReader();
        DataSet ds = new DataSet();
        DropDownList1.DataSource = rd;
        DropDownList1.DataValueField = "PCity";
 Remember to bind the data source to the dropdown list .....
& also bind the column to the drop down list like i did i.e.
DropDownList1.DataValueField = "PCity"
Like this you can bind multiple columns to the dropdown list .... 


Post a Comment