Solved

How to Show/Hide Text field based on radio button values with VB in .aspx

Posted on 2014-03-04
5
625 Views
Last Modified: 2014-03-11
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).Selected)
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("pnlQuestion1" & strID).Visible = blnShow
        End Sub
Thanks for any help.
0
Comment
Question by:newtoperlpgm
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39904818
You set up your radiobuttonlist with yor values and then check the SelectedValue to determine how to proceed. I use a SELECT CASE to that, but you could use an If/Else if you don't have too many items.

 <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
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39912213
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)

Open in new window

0
 

Author Comment

by:newtoperlpgm
ID: 39918954
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.RadioButtonList'.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39920053
Sorry, had an extra item in there. Try it as:
Dim show As Boolean = RBList1.Items(0).Selected Or RBList1.Items(1).Selected
Showtxtfld(strID, show)

Open in new window

0
 

Author Comment

by:newtoperlpgm
ID: 39921956
That worked for me.  Thanks for your help.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xml attribute DTD attribute differences 3 65
Node js - send response after all promises are resolved 1 51
MVC and Angular 2 88
Problem to file 3 67
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now