title: fill drop down list from database dynamically in asp.net c#
body: <p>I have drop down list in asp.net app with c#. The element of drop down list coming from database (names of user). My drop down list showing me selected name as first name appear in my database table by default. i.e. when i open page i saw that name is already selected. I want that, selected name should be like "nworks User". I tried it by using code : </p>
  
  <pre><code> &lt;asp:DropDownList ID="DropDownListSelectEmployee" runat="server" AutoPostBack="true"
                                  OnSelectedIndexChanged="DropDownListSelectEmployee_SelectedIndexChanged"
                                  OnTextChanged="DropDownListSelectEmployee_TextChanged" Height="30px" Width="250px"&gt;
                                  &lt;asp:ListItem Selected="True"&gt;nWorks Employee&lt;/asp:ListItem&gt;
                              &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>but no use. and next option i tried is : <code>DropDownListSelectEmployee.Selecteditem.Text="nWorks User";</code>
  again not worked. I am getting items from database using code : </p>
  
  <pre><code>public void 
  
      DropDownListSelectEmployee_Fill()
              {
                  if (!Page.IsPostBack)
                  {
  
                      DropDownListSelectEmployee.Items.Clear();
  
                      string q = "select username from nworksuser where _type='Employee';";
                      MySqlCommand cmd = new MySqlCommand(q, conn);
                      conn.Open();
                      string user = "";
                      MySqlDataReader rdr = cmd.ExecuteReader();
                      while (rdr.Read())
                      {
                          user = rdr.GetString("username");
                          DropDownListSelectEmployee.Items.Add(user);
                      }
                      conn.Close();
                  }
              }
  </code></pre>
  
  <p>how it is possible?</p>