title: how to get DataValue of dropdownlist in ASP.NET C#
body: <p>i have a problem as subject said.</p>
  
  <p>i have a Table courses in sql server Fields are courseID and course.</p>
  
  <p>what i want is list the course in dopdown and i succeeeded but what i'm not able to do is when i select a course from dropdown list, a courseID should be selected in HiddenField/textbox/label</p>
  
  <p>how to do that</p>
  
  <p>here is a code i tried::</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      string select = "select * from courses";
      DropDownList1.Items.Add("-- Select Course --");
      DropDownList1.SelectedIndex = 0;
      DataTable dt = con.select_command(select);
      for (int i = 0; i &lt; dt.Rows.Count; i++)
      {
          DropDownList1.Items.Add(dt.Rows[i][1].ToString());
          DropDownList1.DataValueField = dt.Rows[i][0].ToString();
          DropDownList1.DataTextField = dt.Rows[i][1].ToString();
      }        
  
  }
  </code></pre>
  
  <p>in dropdownlist i'm getting values in Page Load method</p>
  
  <p>i also tried dropdownlist_selectedindex change method too to select courseID</p>
  
  <pre><code>protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
      LLabel1.Text = DropDownList1.SelectedValue.ToString();
  }
  </code></pre>
  
  <p>what i'm doing wrong ???</p>