title: Dropdownlist in edit mode of a gridview
body: <p>In my application in c#, when I edit a row in the gridview I choose some new data from a dropdownlist.</p>
  
  <p>I am populating the dropdown like this:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Gender"&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:Label ID="gender" runat="server" Text='&lt;%# Eval("gender").ToString() %&gt;'&gt;&lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
      &lt;EditItemTemplate&gt;
          &lt;asp:DropDownList ID="DDL_genderList" runat="server"&gt;
              &lt;asp:ListItem Value="" Text="---"&gt;&lt;/asp:ListItem&gt;
              &lt;asp:ListItem Value="M" Text="M"&gt; &lt;/asp:ListItem&gt;
              &lt;asp:ListItem Value="F" Text="F"&gt; &lt;/asp:ListItem&gt;
          &lt;/asp:DropDownList&gt;
      &lt;/EditItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>But when I press the 'Edit' button from the template and enters in the 'RowUpdating' event, the selected value from the dropdownlist is every time the first value from that dropdownlist.</p>
  
  <p>I need selected value in dropdownlist it's the value which displays in Label gender.</p>
  
  <p>Does anyone have any ideas?</p>
  
  <p>I've tried many ways to set the selected value in the 'RowDataBound' event, but with no luck. </p>
  
  <p>I tried this:</p>
  
  <pre><code>protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      DataRowView dRowView = (DataRowView)e.Row.DataItem;
  
      if ((e.Row.RowState &amp; DataControlRowState.Edit) &gt; 0)
      {
          DropDownList genderList = (DropDownList)e.Row.FindControl("DDL_genderList");
          genderList.SelectedValue = dRowView[1].ToString();
      }
  }
  </code></pre>