Click here to Skip to main content
12,448,720 members (52,073 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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


<%@ 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
Posted 23-Jan-13 22:43pm
Comments
Sheikh Muhammad Haris 25-Jan-13 14:49pm
   
Your question is not clear what you want to do ... Make is a little more clear by Editing your question.
bhavin tanna 29-Jan-13 17:31pm
   
where u call GetRDBValue() javascript function. if it is in .cs then please specify your code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100