Hiding tablerow based on radiobuttonlist selection

Joined
Apr 9, 2009
Messages
1
Reaction score
0
I am having some trouble getting this code to work and I dont know what I missing, any help is greatly appreciated. I have a simple 9 question survey using asp.net, I am using an asp:formview with InsertItemTemplate. In the form I have a radiobuttonlist with yes no values, I have set the radio button list with AutoPostBack=True

Code:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" Height="521px"
            Width="700px" AllowPaging="True" DefaultMode="Insert" BorderStyle="Solid" BorderWidth="1" BackColor="ActiveBorder">
<InsertItemTemplate>
                <table border="1">
                    <tr>
                        <td>
                            1.The IT hardware I use on a daily basis allows me to perform my job duties as needed.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList1" SelectedValue='<%# Bind("Q1") %>' runat="server" RepeatDirection="Horizontal" Width="40px" AutoPostBack="true">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList>
                            
                        </td>
                     </tr>
                     <tr id="comment1" runat="server" visible="false">
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q1CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q1Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>

Code:
If RadioButtonList1.SelectedItem.Value = "no" Then
            Comment1.Visible = True
        Else
            Comment1.Visible = False
        End If

The page loads and inserts fine, however when I select No the page reloads but does not show the textbox required. I have also tried the following code

Code:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" Height="521px"
Width="700px" AllowPaging="True" DefaultMode="Insert" BorderStyle="Solid" BorderWidth="1" BackColor="ActiveBorder" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">

Code:
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        If IsPostBack Then
             If RadioButtonList1.SelectedItem.Value = "no" Then
                 Comment1.Visible = True
             Else
                Comment1.Visible = False
              End If
        End If
    End Sub

Any help is greatly appreciated, I am sure it is something simple I am missing but I cant see it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top