Click here to Skip to main content
15,886,817 members

asp.net with javascript

polinaidu asked:

Open original thread
I have take radiobuttonlist and i have checked one radio the associated Radiobuttons will checked that buttons will inside datalist to radiobuttonlist this process using javascript function plz give me answer


XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>RadioButtonList using Selection</title>
    <script language="javascript" type="text/javascript">

        function GetRDBValue() {
            var radio = document.getElementsByName('rblSelection');

            for (var i = 0; i < radio.length; i++) {

                if (radio[i].checked) {

                    alert(radio[i].value);
                    if (radio[i].value == "1") {
                        var datalist = document.getElementById('<%=dlRadiobtnlist.ClientID%>').childNodes[0];
                        alert(datalist);
                        var rbl = datalist.getElementsByTagName("rblSelection1");
                        alert(rbl);
                        for (var i = 0; i < rbl.length; i++) {
                            if (rbl[i].type == "1") {
                               // alert(rbl[i].options[rbl[i].selectedIndex].value);
                                rbl[i].type.checked = true;
                            }
                        }
                    }

                    if (radio[i].value == "0") {
                        var datalist = document.getElementById('<%=dlRadiobtnlist.ClientID%>').childNodes[0];
                        alert(datalist);
                        var rbl = datalist.getElementsByTagName("rblSelection1");
                        for (var i = 0; i < rbl.length; i++) {
                            if (rbl[i].type == "0") {
                               // alert(rbl[i].options[rbl[i].selectedIndex].value);
                                rbl[i].type.checked = true;
                            }
                        }
                    }

                }

            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:Label ID="lblRblist" runat="server" Text="Radiobutton Selection" ForeColor="Black"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="rblSelection" runat="server" RepeatDirection="Horizontal"
                        AutoPostBack="true" ValidationGroup="g1">
                        <asp:ListItem Value="1">Yes</asp:ListItem>
                        <asp:ListItem Value="0">No</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidat" runat="server" ControlToValidate="rblSelection"
                        ErrorMessage="Please Select one" ForeColor="Red">
                    </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DataList ID="dlRadiobtnlist" runat="server" RepeatColumns="3" RepeatDirection="Vertical"
                        GridLines="Both">
                        <ItemTemplate>
                            <asp:RadioButtonList ID="c" runat="server" RepeatDirection="Vertical" GridLines="Both"
                                AutoPostBack="true" ValidationGroup="g1">
                                <asp:ListItem Value="1">Yes</asp:ListItem>
                                <asp:ListItem Value="0">No</asp:ListItem>
                            </asp:RadioButtonList>
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


This is my code not working please help me
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900