title: How to set Dropdownlist value in asp.net using C#
body: <p>i have a method to populate the dropdownlist in asp.net using C#</p>
  
  <pre><code>public void get_country_box_populated(ref System.Web.UI.WebControls.DropDownList dropDown, bool add_initial_text)
  {
      dropDown.Items.Clear();
      //dropDown.Items.Add(0,"Select Any Country");
      var context = new db_vmartEntities();
      var query = from c in context.tbl_countary
                  where c.status == true
                  select new { c.countary_id, c.countary_name };
  
      var dictionary = new Dictionary&lt;int, string&gt;();
      if (add_initial_text)
      {
          dictionary.Add(0, "Select Any Country");
      }
      foreach (var item in query)
      {
          dictionary.Add(item.countary_id, item.countary_name);
      }
      dropDown.DataTextField = "Value";
      dropDown.DataValueField = "Key";
      dropDown.DataSource = dictionary;  //Dictionary&lt;int, string&gt;
      dropDown.DataBind();
  }
  </code></pre>
  
  <p>now i need to select a default value on edit page something like this.</p>
  
  <pre><code>store_registration my_store = str.get_store_by_id(Session["user"].ToString(), sid);
  c.get_country_box_populated(ref countary_box,false);
  countary_box.Text = countary_box.Items.FindByValue(my_store.countary).ToString();
  </code></pre>
  
  <p>but value in not set because patteren is like this </p>
  
  <pre><code>Dictionary&lt;key,value&gt;
  Dictionary&lt;5,Pakistan&gt;
  Dictionary&lt;8,India&gt;
  Dictionary&lt;9,Iran&gt;
  Dictionary&lt;6,UK&gt;
  </code></pre>
  
  <p>any help or guide if i can set UK in dropdownlist when mystore.country value is 6</p>