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

<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>

On the backend I am using the following 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

<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

Please help, I cannot figure out what I am missing

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

<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>

On the backend I am using the following 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

<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

Please help, I cannot figure out what I am missing

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ITSurvey.aspx.vb" Inherits="departments_informationtechnology_ITSurvey" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>IT Survey</title>
</head>
<body>
    <form id="form1" runat="server">
    
    <div align="center">
    <asp:Label ID="UserID1" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="white"
                Text="UserID"></asp:Label>
                    <table border="1" cellpadding="0" cellspacing="0" width="700">
                            <tr>
                                <td colspan="2" align="center" style="width: 670px">
                                    <span style="font-size: 14pt; font-family: Verdana"></span>
                                    <h1>
                                        <span style="font-size: 14pt; font-family: Verdana">User Opinion Survey</span></h1>
                                    <h1 style="margin: 0in 0in 8pt">
                                        <span style="font-size: 14pt; font-family: Verdana">Information Technology Department</span></h1>
                                </td>
                            </tr>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnStr %>"
            SelectCommand="SELECT [Q1], [Q2], [Q3], [Q4], [Q5], [Q6], [Q7], [Q8], [Q9], [Comments], [Q1Comments], [Q2Comments], [Q3Comments], [Q4Comments], [Q5Comments], [Q6Comments], [Q7Comments], [Q8Comments], [Q9Comments] FROM [ITSurveyResponse]"
            InsertCommand="INSERT into ITSurveyResponse(Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Comments,Q1Comments,Q2Comments,Q3Comments,Q4Comments,Q5Comments,Q6Comments,Q7Comments,Q8Comments,Q9Comments) VALUES (@Q1,@Q2,@Q3,@Q4,@Q5,@Q6,@Q7,@Q7,@Q9,@Comments,@Q1Comments,@Q2Comments,@Q3Comments,@Q4Comments,@Q5Comments,@Q6Comments,@Q7Comments,@Q8Comments,@Q9Comments)" OnInserted="SqlDataSource1_Inserted">
            <InsertParameters>
                <asp:Parameter Name="Q1" />
                <asp:Parameter Name="Q2" />
                <asp:Parameter Name="Q3" />
                <asp:Parameter Name="Q4" />
                <asp:Parameter Name="Q5" />
                <asp:Parameter Name="Q6" />
                <asp:Parameter Name="Q7" />
                <asp:Parameter Name="Q9" />
                <asp:Parameter Name="Comments" />
                <asp:Parameter Name="Q1Comments" />
                <asp:Parameter Name="Q2Comments" />
                <asp:Parameter Name="Q3Comments" />
                <asp:Parameter Name="Q4Comments" />
                <asp:Parameter Name="Q5Comments" />
                <asp:Parameter Name="Q6Comments" />
                <asp:Parameter Name="Q7Comments" />
                <asp:Parameter Name="Q8Comments" />
                <asp:Parameter Name="Q9Comments" />
            </InsertParameters>
        </asp:SqlDataSource>
        &nbsp;&nbsp;
        </table>
        <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>
                    
                    <tr>
                        <td>
                            2. When I have a problem with my computer, the IT department is responsive and handles the issue quickly and efficiently.
                         </td>
                         <td>
                            <asp:RadioButtonList ID="RadioButtonList2" SelectedValue='<%# Bind("Q2") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q2CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q2Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>
                    <tr>
                        <td>
                            3.When I request new hardware to perform a specific task, the IT Department provides the equipment needed effectively.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList3" SelectedValue='<%# Bind("Q3") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q3CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q3Comments") %>'>
                            </asp:TextBox><br />
                         </td>
                    </tr>
                    <tr>
                        <td>
                            4.When I request new software to be developed or purchased, the IT Department provides good support and solutions.
                        </td>
                        <td>    
                            <asp:RadioButtonList ID="RadioButtonList4" SelectedValue='<%# Bind("Q4") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q4CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q4Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>                   
                    <tr>
                        <td>     
                            5.I am adequately trained in using the hardware and software needed to fulfill my job duties.
                        </td>
                        <td>    
                            <asp:RadioButtonList ID="RadioButtonList5" SelectedValue='<%# Bind("Q5") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q5CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q5Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>                    
                    <tr>
                        <td>        
                            6.Current network speeds allow  me to access files & web content quickly.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList6" SelectedValue='<%# Bind("Q6") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q6CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q6Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>                   
                    <tr>
                        <td>                            
                            7.The telephone equipment I use daily provides a quality of service that is consistently good.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList7" SelectedValue='<%# Bind("Q7") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q7CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q7Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>                    
                    <tr>
                        <td>                            
                            8.The EDEN ERP system supports me in the performance of my job duties.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList8" SelectedValue='<%# Bind("Q8") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q8CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q8Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>
                    <tr>
                        <td>                           
                            9.The Department specific software I use, (i.e.. Class, PODS, Comply, HEAT, OSSI/RMS, Trim, Faster, etc..) is reliable and well supported by the IT Department.
                        </td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList9" SelectedValue='<%# Bind("Q9") %>' runat="server" RepeatDirection="Horizontal" Width="40px">
                                <asp:ListItem Value='yes'>Yes</asp:ListItem>
                                <asp:ListItem Value='No'>No</asp:ListItem>
                            </asp:RadioButtonList><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">If no please explain<br />
                            <asp:TextBox ID="Q9CommentsTextBox" runat="server" Rows="4" TextMode="MultiLine" Text='<%# Bind("Q9Comments") %>'>
                            </asp:TextBox>
                         </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">               
                            Additional Comments:<br />
                            <asp:TextBox ID="Comments" runat="server" Rows="4" Columns="20" TextMode="MultiLine" Text='<%# Bind("Comments") %>'>
                            </asp:TextBox>
                        </td>
                    <tr align="center">
                        <td colspan="2">
                            <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                Text="Submit">
                            </asp:Button>
                        </td>
                    </tr>
                
                <!--<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>-->
                </table>
            </InsertItemTemplate>
            <PagerTemplate>
            Page: <%#formView1.PageIndex+1%>
                <asp:LinkButton ID="btnPrev" runat="server" CommandArgument="Prev" CommandName="Page">Prev</asp:LinkButton>
                <asp:LinkButton ID="btnNext" runat="server" CommandArgument="Next" CommandName="Page">LinkButton</asp:LinkButton>
            </PagerTemplate>
            
        </asp:FormView></div>
        <!--<asp:textbox id="UserID" Runat="server"></asp:textbox>-->
    </form>
</body>
</html>
Partial Class departments_informationtechnology_ITSUrvey
    Inherits System.Web.UI.Page
    Protected WithEvents RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList
    Protected WithEvents Comment1 As System.Web.UI.WebControls.TableRow
    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        'If Page.IsPostBack Then
        'Dim RadioButtonList1 As New RadioButtonList
        If RadioButtonList1.SelectedItem.Value = "no" Then
            Comment1.Visible = True
        Else
            Comment1.Visible = False
        End If
        'End If

    End Sub
    Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
        Response.Redirect("ThankYou.aspx")
    End Sub
End Class

Hi,

Try like this

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) 
        Dim rd As RadioButtonList

        rd = CType(sender, RadioButtonList)
        Dim tr As HtmlTableRow

        tr = CType(FormView1.FindControl("comment1"), HtmlTableRow)



        If rd.SelectedItem.Value = "No" Then
            tr.Visible = True
        Else
            tr.Visible = False
        End If


    End Sub

Thanks for the suggestion but it still doesnt work, and I just dont understand why. Your suggestion makes sense but it seems to be missing something. Using the example you provided witht he radiobuttonlist autopost set to true once I click no the page is reoladed but the box never shows. In fact unless i hide the row with in the tr <tr visible="false"> the tr is always visible, once I add the visible property to false, i select no and the box never shows. I am at a loss with this code.

This article has been dead for over six months. Start a new discussion instead.