title: Dropdownlist in gridview control selecting the first index only
body: <p>I have a dropdownlist control in a gridview control. The grid view control and the dropdown are connected to a datasource.</p>
  
  <p>On submit, the dropdown control only picks the value of the first index.</p>
  
  <p>Here's the ASPX Code:</p>
  
  <pre><code>&lt;asp:GridView ID="gvQuestions" runat="server" AutoGenerateColumns="False" CellPadding="4"
      ForeColor="#333333" GridLines="None"&gt;
      &lt;AlternatingRowStyle BackColor="White" /&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="qID" HeaderText="QID" /&gt;
          &lt;asp:BoundField DataField="Question" HeaderText="Questions" /&gt;
          &lt;asp:TemplateField HeaderText="Response"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:DropDownList ID="ddlResponse" runat="server" AppendDataBoundItems="True" AutoPostBack="false"
                      DataSourceID="ResponseSDS" DataTextField="response" DataValueField="responseID"
                      CssClass="ddlStyle" OnSelectedIndexChanged="ddlResponse_SelectedIndexChanged"&gt;
                      &lt;%--&lt;asp:ListItem Enabled="True" Selected="false"&gt;&lt;--Selected Value--&gt;&lt;/asp:ListItem&gt;--%&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:SqlDataSource ID="ResponseSDS" runat="server" ConnectionString="&lt;%$ ConnectionStrings:HSELeadershipSurveyConnectionString %&gt;"
                      SelectCommand="SELECT * FROM [tblResponse]"&gt;&lt;/asp:SqlDataSource&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
      &lt;EditRowStyle BackColor="#2461BF" /&gt;
      &lt;FooterStyle BackColor="#0085C9" Font-Bold="True" ForeColor="White" /&gt;
      &lt;HeaderStyle BackColor="#0085C9" Font-Bold="True" ForeColor="White" /&gt;
      &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="#EFF3FB" /&gt;
      &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>And here's the code behind for the button click event:</p>
  
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
  {
      // Get the responses for the questions
      foreach (GridViewRow masterData in gvQuestions.Rows)
      {
          qID = int.Parse(masterData.Cells[0].Text);
          //qID = (int)gvQuestions.DataKeys[(masterData.RowIndex)].Value;
          //response = ((DropDownList)masterData.FindControl("ddlResponse")).SelectedValue.ToString();
          DropDownList ddl = (DropDownList)gvQuestions.Rows[qID].FindControl("ddlResponse");
          responses = ddl.SelectedValue.ToString();
      }
  
  }
  </code></pre>