Click here to Skip to main content
16,016,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Comments
[no name] 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)



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