Solved

How to hide/display text box based on radio buttons

Posted on 2013-02-03
4
433 Views
Last Modified: 2013-02-21
Hello there.

This is my problem: I have in an input form a radio button  created within the same form, which captures for the app a value, based on wich there are textboxes which should be displayed/hidden. This proyect is coded in VB.NET behind a VS module with MS SQL Server db as BE.
0
Comment
Question by:LUISOFO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 38849816
<asp:RadioButton ID="rb1" runat="server" AutoPostBack="true" 
            oncheckedchanged="rb1_CheckedChanged" />

protected void rb1_CheckedChanged(object sender, EventArgs e)
        {
            txt2.Visible = true;
        }

Open in new window

0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 38849976
try

document.getElementById('controlid').style.display='block';

'controlid is ur textbox name in page (see in view source and give textbox name)

morehttp://forums.asp.net/t/1479133.aspx/1?javascript+to+hide+control+on+radio+button+click
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38849988
u can make use of javascript also to make this done

<input type="radio" class="yesRadio" onClick="showTextBox()"/>

<input type="text" class="textBox" hidden/>

Open in new window


use script
[b]  <script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>[/b]
<script type="text/javascript>
function showTextBox() {
$(".textBox").show();
}
</script>

Open in new window


http://www.hscripts.com/tutorials/javascript/dom/radio-events.php

<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
Do include the script file under js folder in your project., if dont have download from here
http://jquery.com/download/

or

u can use
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
Need Internet access for above URl
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38872463
You can use the asp:RadioButtonList OnSelectedIndexChanged event to loop through the controls in an asp:FormView, get a handle on the controls you want to toggle visibility for.

Here's a sample showing how to loop through all controls in the ReadOnly Template of an asp:FormView, setting visibility of certain TextBox controls based on the Text value of the selected RadioButtonList item:
<%@ Page Language="VB" %>

<!DOCTYPE html>

<script runat="server">

    Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim fv As FormView = Nothing
        Dim tb As TextBox = Nothing
       If TypeOf sender.namingcontainer Is FormView Then
            fv = sender.namingcontainer
            If fv.CurrentMode = FormViewMode.ReadOnly Then
                
                For Each t As Table In fv.Controls
                    For Each r As TableRow In t.Rows
                        For Each c As TableCell In r.Cells
                            For Each ctl As Control In c.Controls
                                If TypeOf ctl Is TextBox Then
                                    If ctl.ID.Contains(sender.Text) Then
                                        ctl.Visible = True
                                        tb = ctl
                                        tb.Text = ctl.ID.ToString
                                    Else
                                        ctl.Visible = False
                                    End If
                                End If
                            Next
                        Next
                    Next
                Next
            End If
        End If

    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID")%>' />
                <br />
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"  OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                    <asp:ListItem>Group1</asp:ListItem>
                    <asp:ListItem>Group2</asp:ListItem>
                </asp:RadioButtonList>
                <br />
                <br />
                <!-- Group1 controls -->
                <asp:TextBox ID="TextBox1_Group1" runat="server" Visible="false" BackColor="LemonChiffon" />
                <asp:TextBox ID="TextBox2_Group1" runat="server" Visible="false" BackColor="LemonChiffon" />
                <!-- Group2 controls -->
                <asp:TextBox ID="TextBox1_Group2" runat="server" Visible="false" BackColor="LemonChiffon" />
                <asp:TextBox ID="TextBox2_Group2" runat="server" Visible="false" BackColor="LemonChiffon" />
            </ItemTemplate>
        </asp:FormView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select 1 as ID union all select 2 union all select 3" ConnectionString="<%$ ConnectionStrings:cnAkoJo %>"></asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Open in new window

Alan
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net figure out error 3 26
asp.net, radiobuttonlist, c# 3 39
SQL - Ordering Supervisor Hierarchy 2 15
Need to find substring in SQL 3 15
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

730 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