title: How to get ID against selected value of Dropdownlist C#
body: <p>How can I get the ID against the selected value of a DropDownList which is bound with DB?</p>
  
  <p>Then how can I insert this ID into another table?</p>
  
  <p>To get ID code</p>
  
  <pre><code>string query = "Select ID From Table-1 Where Name=" + DropDwonList.SelectedValue;
  SqlCommand cmd = new SqlCommand(query, con);
  SqlDataReader dr = cmd.ExecuteReader();
  string getId = dr[0].ToString();
  </code></pre>
  
  <p>DropDownList Binding Code</p>
  
  <pre><code>string query = "Select ID, Name from Table-1";
  SqlConnection con = new SqlConnection(conStr);
  SqlDataAdapter da = new SqlDataAdapter(query, con);
  DataTable dt = new DataTable();
  da.Fill(dt);
  DropDwonList.DataSource = dt;
  DropDwonList.DataTextField = "Name";
  DropDwonList.DataValueField = "ID";
  DropDwonList.DataBind();
  DropDwonList.Items.Insert(0, new ListItem("--Select Name--"));
  </code></pre>