Link to home
Start Free TrialLog in
Avatar of enrique_aeo
enrique_aeo

asked on

<asp:RadioButtonList get value in the code behind

hi guys, as I can get and value of what the user has selectionof? to process it in the code behind
SOLUTION
Avatar of JayFromPep
JayFromPep
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
In code behind you have :

rblSeguimientoCritica.SelectedValue

and

rblInovacionFundada.SelectedValue
If you want to get at client side, use :


function getSelectedValue(rbListName) {
        var inputs = document.forms[0].getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if ( inputs[i].name.indexOf(rbListName)>=0 && inputs[i].type == "radio" && inputs[i].checked) return inputs[i].value;
        }
    }

Open in new window

example of using :


<table>
<tr class="TableItemAltFirst">
                <td class="style4">Seguimiento o crítica fundada en los precedentes. Universalidad.</td>
                <td>
                    <asp:RadioButtonList ID="rblSeguimientoCritica" runat="server" RepeatDirection="Horizontal" >
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                    </asp:RadioButtonList>
                </td>            
            </tr>
            <tr class="TableItemAltSecond">
                <td class="style4">Innovación fundada en la interpretación creativa, posible y razonable del derecho, o del ordenamiento jurídico.</td>
                <td>
                    <asp:RadioButtonList ID="rblInovacionFundada" runat="server" RepeatDirection="Horizontal" >
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                    </asp:RadioButtonList>
                </td>          
            </tr>
            </table>
<script language="javascript" type="text/javascript">
    function checkRadioIsSet() {
        var inputs = document.forms[0].getElementsByTagName("input");
        var allForEachGroupIsChecked = true;
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "radio") {
                var oneIsChecked = false;
                var lastName = inputs[i].name;
                while (lastName == inputs[i].name) {
                    if (inputs[i].checked) oneIsChecked = true;
                    i++;
                }
                i--;
                allForEachGroupIsChecked = allForEachGroupIsChecked && oneIsChecked;
            }
        }
        if (allForEachGroupIsChecked) {
            return allForEachGroupIsChecked;
        }
        else {
            alert("choose an answer for all questions!");
            return allForEachGroupIsChecked;
        }
    }
    function getSelectedValue(rbListName) {
        var inputs = document.forms[0].getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if ( inputs[i].name.indexOf(rbListName)>=0 && inputs[i].type == "radio" && inputs[i].checked) return inputs[i].value;
        }
    }
</script>
<asp:Button ID="btnSave" runat="server" Text="Grabar Informacion" OnClientClick="return checkRadioIsSet();" />
<asp:Button ID="Button1" runat="server" Text="get selected value for Seguimiento Critica" OnClientClick="alert(getSelectedValue('rblSeguimientoCritica'));" />
<asp:Button ID="Button2" runat="server" Text="get selected value for Inovacion Fundada" OnClientClick="alert(getSelectedValue('rblInovacionFundada'));" />

Open in new window

Avatar of enrique_aeo
enrique_aeo

ASKER

Please leakim971,
please, could you complete the example in the code behind?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial