title: Populate dropdownlist with datareader from database
body: <p>Problem with populate specific dropdownlist values from database, i want to shows user all the current data from database tables to let them able to make changes, but i coulnd't shows the specific dropdownlist that user selected before. Im using linqdatasource to show all the dropdownlist value.</p>
  
  <pre><code>public partial class Update : System.Web.UI.Page
  {
      string cs = Global.CS;    
      DataClasses1DataContext db = new DataClasses1DataContext();
  
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!Page.IsPostBack) // only during initial load
          {
              string id = Request.QueryString["Item_ID"] ?? "";
  
              string sql = "Select * FROM MenuItem WHERE Item_ID = @id";
  
  
              SqlConnection con = new SqlConnection(cs);
              SqlCommand cmd = new SqlCommand(sql, con);
  
              cmd.Parameters.AddWithValue("@Id", id);
  
              con.Open();
              SqlDataReader dr = cmd.ExecuteReader();
  
              if (dr.Read())
              {
                  if ((string)dr["Category"] == "Breakfast" || (string)dr["Category"] == "Lunch" || (string)dr["Category"] == "Dinner")
                  {
                      DataBind();
                      lblId.Text = (string)dr["Item_ID"].ToString();
                      txtItemName.Text = (string)dr["ItemDesc"];
                      txtPrice.Text = (string)dr["Price"].ToString();
                      ddlCategory.Text = (string)dr["Category"];
  
  
  
  
                          //foreach (var checking in db.Sets)
                          //{
                          //    string setID = checking.Set_ID.ToString();
                          //    if (setID == (string)dr["Item_ID"])
                          //    {
                          //        ddlAlacarte.DataSourceID = "ldsAlacarte";
                          //        **ddlAlacarte.DataTextField = (string)dr["ItemDesc"].ToString();
                          //        ddlAlacarte.DataValueField = (string)dr["Item_ID"].ToString();**
                          //    }
                          //}                            
  
  
  
  
                  }
                  else
                  {
                      ddlAlacarte.Enabled = false;
                      ddlBeverage.Enabled = false;
                      ddlSide.Enabled = false;
                      DataBind();
  
                      lblId.Text = (string)dr["Item_ID"].ToString();
                      txtItemName.Text = (string)dr["ItemDesc"];
                      txtPrice.Text = (string)dr["Price"].ToString();
                      ddlCategory.Text = (string)dr["Category"];
  
  
                  }
              }
              else
              {
                  Response.Redirect("MenuAdmin.aspx");
              }
              DataBind();
              dr.Close();
              con.Close();
          }
      }
      protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (ddlCategory.SelectedItem.Text == "Breakfast" || ddlCategory.SelectedItem.Text == "Lunch" || ddlCategory.SelectedItem.Text == "Dinner")
          {
              ddlAlacarte.Enabled = true;
              ddlBeverage.Enabled = true;
              ddlSide.Enabled = true;
              DataBind();
          }
          else
          {
              ddlAlacarte.Enabled = false;
              ddlBeverage.Enabled = false;
              ddlSide.Enabled = false;
              DataBind();
          }
      }
  
  }
  </code></pre>