newtoperlpgm
asked on
How to Show/Hide Text field based on radio button values with VB in .aspx
I am new to vb.net and have to change code to display a text field for more than one condition.
Right now, the text box only displays for one radio button list value. I'd like it to display for two values, but there is also an N/A value. The values are Not Safe, Safe, and N/A
The code is as follows:
Showtxtfield(strID, rblButton.Item.Item(1).Sel ected)
I changed it to Showtxtfield(strID, True) to display regardless of the value of the radio button, but that displays it for all three radio button values, and I only want it for two, not the third, which is N/A. The subroutine for Showtxtfield is as follows:
Private Sub Showtxtfield(ByVal strID As String, ByVal blnShow As Boolean)
' Show the text box and radio buttons
tblCategory.FindControl("p nlQuestion 1" & strID).Visible = blnShow
End Sub
Thanks for any help.
Right now, the text box only displays for one radio button list value. I'd like it to display for two values, but there is also an N/A value. The values are Not Safe, Safe, and N/A
The code is as follows:
Showtxtfield(strID, rblButton.Item.Item(1).Sel
I changed it to Showtxtfield(strID, True) to display regardless of the value of the radio button, but that displays it for all three radio button values, and I only want it for two, not the third, which is N/A. The subroutine for Showtxtfield is as follows:
Private Sub Showtxtfield(ByVal strID As String, ByVal blnShow As Boolean)
' Show the text box and radio buttons
tblCategory.FindControl("p
End Sub
Thanks for any help.
You need to separate out your logic slightly. Try something like:
Dim show As Boolean = rblButton.Item.Item(1).Selected Or rblButton.Item.Item(2).Selected
Showtxtfield(strID, show)
ASKER
Carl Tawn,
I tried your suggestion, however, I get the following error. I am fairly new to VB.net. Thanks.
Compiler Error Message: BC30456: 'Item' is not a member of 'System.Web.UI.WebControls .RadioButt onList'.
I tried your suggestion, however, I get the following error. I am fairly new to VB.net. Thanks.
Compiler Error Message: BC30456: 'Item' is not a member of 'System.Web.UI.WebControls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked for me. Thanks for your help.
<asp:RadioButtonList ID="rb" runat="server" TextAlign="Right" AutoPostBack="true" >
<asp:ListItem Text="XML File" Value="1" />
<asp:ListItem Text="Import" Value="2" />
<asp:ListItem Text="Report" Value="3" />
<asp:ListItem Text="Bills" Value="4" />
<asp:ListItem Text="Excel" Value="5" />
</asp:RadioButtonList>
Select Case rb.SelectedValue
Case "1L"
'do stuff
Case "2"
'do stuff
Case "3"
'do stuff
Case "4"
'do stuff
Case "5"
'do stuff
End Select