5
Answers

HI. I trying to populate dropdownlist with values in the database in asp.net. But its not working:(

Deepali Patil

Deepali Patil

12y
2.4k
1
Here is my code:

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[0].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from Student1", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            drpdownlist.DataTextField = ds.Tables[0].Columns["FullName"].ToString();
            drpdownlist.DataValueField = ds.Tables[0].Columns["Id"].ToString();
            drpdownlist.DataSource = ds.Tables[0];
            drpdownlist.DataBind();

Its giving problem for the first line.
Please help.

Answers (5)