2
I have several RadioButtonList in a form, in the event of submitting the form I want to go through them and get the selected value.
I tried that:
    protected void btnEnviarQuestionario_Click(object sender, EventArgs e)
    {
        Resposta resposta = new Resposta();
        // criar a resposta a partir dos dados do usuario
        resposta.RA = Convert.ToInt32(dropdownAluno.SelectedValue);
        resposta.EscolaEnsinoFundamental = txtEscolaEnsinoFundamental.Text;
        resposta.Expectativas = txtExpectativa.Value;
        resposta.Linguagens = txtLinguagens.Value;
        // percorre as perguntas para criar o vetor de alternativas
        char[] alternativas = new char[14];
        for (int i = 0; i < 14; i++)
        {
            RadioButtonList rbl = FindControl("rblResp" + (i>9?"":"0") + i) as RadioButtonList;
            //if (rbl != null)
            //alternativas[i] = Convert.ToChar(rbl.SelectedValue);
        }
        resposta.Respostas = alternativas;
        // enviar resposta para o banco de dados
        _respostaBo = new RespostaBo();
        try
        {
            _respostaBo.EnviarQuestionario(resposta);
            lblStatus.Text = "Questionário enviado!";
        }
        catch
        {
            lblStatus.Text = "Erro ao enviar questionário! ^_^";
        }
    }
Inside the Masterpage I’m using, after the tag <body>, possesses:
    <form id="form1" runat="server">
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="~/Home/Home.aspx" runat="server">
                    <img alt="Questionário" class="img-responsive" src="~/images/questionario.png" runat="server" />
                </a>
            </div>
            <p class="navbar-text">
                <asp:Label ID="lblNomeDaPagina" runat="server" Text="Nome da Página"></asp:Label></p>
        </div>
    </nav>
    <div class="container">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    <script src="../scripts/jquery-1.9.1.min.js"></script>
    <script src="../scripts/bootstrap.min.js"></script>
</form>
On the page I’m using Masterpage:
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Panel ID="panelQuestionarios" runat="server">
    <div class="form-horizontal">
        <div class="form-group">
            <asp:Label ID="lblPergunta" CssClass="col-sm-2 control-label" runat="server" Text="1. Qual a pergunta?"></asp:Label>
            <div class="col-sm-10">
                <%-- Alternativas --%>
                <asp:RadioButtonList ID="rblResp01" runat="server">
                    <asp:ListItem Value="A">x</asp:ListItem>
                    <asp:ListItem Value="B">x</asp:ListItem>
                    <asp:ListItem Value="C">x</asp:ListItem>
                    <asp:ListItem Value="D">x</asp:ListItem>
                    <asp:ListItem Value="E">x</asp:ListItem>
                </asp:RadioButtonList>
            </div>
        </div>
   <!-- Mais 13 perguntas iguais acima, simplifiquei o código -->
        <div class="form-group">
            <div class="col-sm-2"></div>
            <div class="col-sm-10">
                <asp:Button ID="btnEnviarQuestionario" CssClass="btn-success btn" runat="server" Text="Enviar questionário" OnClick="btnEnviarQuestionario_Click" />
            </div>
        </div>
    </div>
    </asp:Panel>
</asp:Content>
rbl is getting null. How to select Radiobuttonlist?
The radioButtonList have the names as "rblResp01, rblResp02, ..." The problem would be that I do not find them
– Bart
put all the code
.ASPXplease in your question, edit.– novic
Is Bart the page??? also
– novic
rblResp01.SelectValueThat’s not all @Bart?– Marconi
@Marconi after having managed to access the control just do it! The problem was that I could not access it...
– Bart