Deepali Patil

Deepali Patil

  • NA
  • 142
  • 56.1k

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

Oct 13 2012 3:53 AM
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)