title: Set textbox visibility based on dropdownlist value in gridview
body: <p>I have a gridview that i would like to show or hide a text box based on the selected value of a dropdownlist on the same row.</p>
  
  <p>My gridview:</p>
  
  <pre><code>                &lt;asp:GridView ID="GridViewUsers" runat="server" AutoGenerateColumns="False" CssClass="TableFramed"&gt;
                  &lt;Columns&gt;
                      &lt;asp:TemplateField HeaderText="Type"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:DropDownList ID="ddlType" runat="server" AutoPostBack="true"&gt;
                                  &lt;asp:ListItem Value="1"&gt;Overtime&lt;/asp:ListItem&gt;
                                  &lt;asp:ListItem Value="2"&gt;Temporary&lt;/asp:ListItem&gt;
                                  &lt;asp:ListItem Value="3"&gt;Permanent&lt;/asp:ListItem&gt;
                              &lt;/asp:DropDownList&gt;
                          &lt;/ItemTemplate&gt;                        
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="First Name"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:TextBox ID="txtFName" runat="server"&gt;&lt;/asp:TextBox&gt;
                              &lt;asp:RequiredFieldValidator ID="FNameValidator" runat="server" Text="*" ControlToValidate="txtFName" Display="Dynamic"&gt;&lt;/asp:RequiredFieldValidator&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;asp:TemplateField HeaderText="hide me"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:TextBox ID="txtHideMe" runat="server"&gt;&lt;/asp:TextBox&gt;
                          &lt;/ItemTemplate&gt;
                  &lt;/Columns&gt;
               &lt;/asp:gridview&gt;
  </code></pre>
  
  <p>How do i wire it up so that the <code>txtHideMe</code> textbox can be hidden or displayed based off of the selected value of the dropdownlist?</p>
  
  <p>Codebehide:</p>
  
  <pre><code>   Protected Sub ddlType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
          For Each row In GridViewUsers.Rows
              Dim reqType As DropDownList = CType(row.FindControl("ddlType"), DropDownList)
              Dim txtHideMeAs TextBox = CType(row.FindControl("txtHideMe"), TextBox)
  
              If reqType.SelectedItem.Value = "2" Then
                  txtHideMe.Visible = "False"
              End If
          Next
      End Sub
  </code></pre>
  
  <p>Edit:
  I would also like to be able to use a required field validator on the textbox if it's not hidden.</p>