bind two column into a dropdown

asp.net, c#

Solution

Its Name1 not name1

change this to

DropDownList3.DataTextField = "Name1";

EDIT:

You are binding a string(query) to datasource here

DropDownList3.DataSource = query;

and string dont have a property with the name 'name1',so error

SOLUTION :

refer this,I have changed this for your requirement

private void LoadDropDownList()
        {
            SqlConnection con=new SqlConnection(CommonRefference.Constr());
            string query = "Select Id,Name+' ('+Distribution_name+') 'as Name1 from BR_supervisor  ";

            SqlCommand cmd = new SqlCommand(query,con);
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            DropDownList3.DataSource = reader ;

            DropDownList3.DataValueField = "Id";
            DropDownList3.DataTextField = "Name1";

            DropDownList3.DataBind();

            DropDownList3.Items.Insert(0, new ListItem("Select One", "0")); // Adds items to the DDL
            DropDownList3.Items.Insert(1, new ListItem("All Categories", "-1"));

            con.Close();
        }

For more explanation refer this link Populate-ASP.NET-dropdownlist

Problem

I want to bind two column from database into dropdownlist. Here's my code: ``` SqlConnection con=new SqlConnection(CommonRefference.Constr()); string query = "Select Id,Name+' ('+Distribution_name+') 'as Name1 from BR_supervisor "; SqlCommand cmd = new SqlCommand(query,con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DropDownList3.DataSource = query; DropDownList3.DataTextField = "name1"; DropDownList3.DataValueField = "Id"; DropDownList3.DataBind(); } con.Close(); ``` But it gives the following error DataBinding: 'System.Char' does not contain a property with the name 'name1' How to do it? Anyone helps me is highly appreciated

Original source