title: ASP.NET - Get DropDownList SelectedValue for current Row when using RowCommand
body: <ul>
  <li><p>When I run the row command event from a button on a gridview row I
  can detect the correct value from any field found on the eventrow.</p></li>
  <li><p><code>hidID</code> which is a unique identifier reports correctly for each row as
  expected.</p></li>
  <li><p><code>ddlVal</code> always reports the first item in the list and not the
  currently selected value.</p></li>
  <li><p>Can anyone offer explanation as to why a dropdownlist would not
  detect the currently selected value when using the command event?</p></li>
  </ul>
  
  <hr>
  
  <p><strong>ASP.NET</strong></p>
  
  <pre><code>  &lt;asp:GridView ID="gv" runat="Server" AutoGenerateColumns="False" OnRowCommand="gv_RowCommand" EnableModelValidation="False"&gt;
      &lt;Columns&gt;
        &lt;asp:TemplateField HeaderText="Reason Missed" ItemStyle-CssClass="Inline" HeaderStyle-CssClass="NoSort" Visible="false"&gt;
          &lt;ItemTemplate&gt;
            &lt;asp:DropDownList ID="ddl" runat="server" DataSourceID="sqldatasource" DataValueField="ID" DataTextField="Text" AppendDataBoundItems="true"&gt;
              &lt;asp:ListItem Text="Select ..." Value="0"/&gt;
            &lt;/asp:DropDownList&gt;
          &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
  
  &lt;asp:SqlDataSource ID="sqldatasource" runat="Server" SelectCommand="sp" SelectCommandType="StoredProcedure"/&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>VB</strong></p>
  
  <pre><code>Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim constring = ConfigurationManager.ConnectionStrings("Con").ConnectionString
    sqldatasource.ConnectionString = constring
  
    Bind_gv()
  End Sub
  
  Protected Sub gv_RowCommand(sender As Object, e As GridViewCommandEventArgs)
    Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
    Dim row As GridViewRow = gv.Rows(rowIndex)
    Dim ddlVal As Integer = DirectCast(row.FindControl("ddl"), DropDownList).SelectedValue
    Dim hidID As Integer = DirectCast(row.FindControl("hidID"), HiddenField).Value
    'ETC ...
  End Sub
  </code></pre>