Hiding tablerow based on radiobuttonlist selection

Discussion in '.NET' started by chief21, Apr 9, 2009.

  1. chief21

    chief21

    Joined:
    Apr 9, 2009
    Messages:
    1
    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.
    chief21, Apr 9, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. frank
    Replies:
    0
    Views:
    327
    frank
    Jul 11, 2003
  2. Steve - DND

    Click Event for TableRow?

    Steve - DND, Jul 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    508
    Steve - DND
    Jul 31, 2003
  3. George Durzi

    TableRow/TableCell Serverside Q

    George Durzi, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    709
    Nicole Calinoiu
    Nov 5, 2003
  4. Coleen

    Span in an ASP TableRow

    Coleen, Jan 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    438
    coleenholley
    Jan 26, 2004
  5. middletree
    Replies:
    4
    Views:
    93
    middletree
    Jan 14, 2005
Loading...

Share This Page