verify that Radiobutton with Repeatdirection, generated in Datagrid are checked

Asked

Viewed 43 times

1

I have a Radionbutton with Repeatdirection which is generated on my Datagrid, yes and no button.

<asp:TemplateColumn HeaderText ="Reevio" ItemStyle-Wrap="false" ItemStyle-Font-Size="8" HeaderStyle-Font-Size="9">
                    <ItemTemplate>                         
                        <asp:RadioButtonList ID="RBLIndicaReenvio" runat="server" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="RBLIndicaReevio_SelectedIndexChanged">     
                            <asp:ListItem Value="S" Text="Sim" ></asp:ListItem>
                            <asp:ListItem Value="N" Text="Não" Selected="true"></asp:ListItem>
                        </asp:RadioButtonList>
                    </ItemTemplate>
                </asp:TemplateColumn>

And here, I have a txb and a button also generated in the grid.

                <asp:TemplateColumn HeaderText ="Digite Seu E-Mail" Visible ="false" ItemStyle-Wrap="false" ItemStyle-Font-Size="8" HeaderStyle-Font-Size="9">
                    <ItemTemplate >
                        <asp:TextBox ID="TXBEmail" Visible ="false" runat="server" Width="200" CssClass="txbEmail" ></asp:TextBox>
                        <asp:Button ID="BTNEnviar" Visible ="false" runat="server" Text="Enviar" Width="60" OnClick="BTNEnviar_Click"></asp:Button>
                    </ItemTemplate>
                </asp:TemplateColumn>

inserir a descrição da imagem aqui

This is code Behind

protected void RBLIndicaReevio_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList objectClick = (RadioButtonList)sender;
        int columnReenvio = Util.getColIndexByHeader(dgRegistros, "Digite Seu E-Mail");

        foreach (DataGridItem dr in dgRegistros.Items)
        {
            RadioButtonList radio;
            TextBox email;
            Button enviar;

            radio = ((RadioButtonList)dr.Cells[columnReenvio].FindControl("RBLIndicaReenvio"));
            email = ((TextBox)dr.Cells[columnReenvio].FindControl("TXBEmail"));
            enviar = ((Button)dr.Cells[columnReenvio].FindControl("BTNEnviar"));

            if (radio == objectClick)
            {
                if (radio.SelectedValue == "S")
                {
                    dgRegistros.Columns[Util.getColIndexByHeader(dgRegistros, "Digite Seu E-Mail")].Visible = true;
                    dr.Cells[columnReenvio].Visible = true;
                    enviar.Visible = true;
                    email.Visible = true;
                }
                else
                {
                    //dgRegistros.Columns[Util.getColIndexByHeader(dgRegistros, "Digite Seu E-Mail")].Visible = false;

                    dr.Cells[columnReenvio].Visible = true;
                    enviar.Visible = false;
                    email.Visible = false;

                }
            }

        }

how could I validate if all the radios are as No ?

2 answers

2


You can do it this way:

  bool todosOpcaoSim = true;
  foreach (DataGridItem dtR in dgRegistros.Items)
  {
    RadioButtonList radio = (RadioButtonList)dtR.Cells[columnReenvio].FindControl("RBLIndicaReenvio"));

    if (radio.SelectedValue.Equals("N"))
      todosOpcaoSim = false;
  }

After passing through this code block your variable will save if all are marked or not as yes.

  • show man! thanks for the help. I got another way.

  • I counted the number of lines and compared with the number of selected buttons. &#xA;&#xA;&#xA;int rowCount = dgRegistros.Items.Count;&#xA; int countRadio = 0;&#xA;&#xA; RadioButtonList radioaux;&#xA;&#xA; foreach (DataGridItem dr in dgRegistros.Items)&#xA; {&#xA; radioaux = ((RadioButtonList)dr.Cells[columnReenvio].FindControl("RBLIndicaReenvio"));&#xA; if (radioaux.SelectedValue == "N")&#xA; {&#xA; countRadio = countRadio + 1;&#xA; }&#xA;&#xA; }

  • The logic is pretty much the same, what changes is that you used a counter instead of a boolean. Don’t forget to mark the answer that solved your problem so you can close the topic

  • Yes man, I did it after I read your answer, thanks :D

-1

I was able to solve by counting the numbers of lines and buttons selected, and comparing the 2 :D

        int rowCount = dgRegistros.Items.Count;

        int countRadio = 0;

        RadioButtonList radioaux;

        foreach (DataGridItem dr in dgRegistros.Items)
        {
            radioaux = ((RadioButtonList)dr.Cells[columnReenvio].FindControl("RBLIndicaReenvio"));
            if (radioaux.SelectedValue == "N")
            {
                countRadio = countRadio + 1;
            }

        }

        if (countRadio == rowCount)
        {
            dgRegistros.Columns[Util.getColIndexByHeader(dgRegistros, "Digite Seu E-Mail")].Visible = false;
        }
        else
        {
            dgRegistros.Columns[Util.getColIndexByHeader(dgRegistros, "Digite Seu E-Mail")].Visible = true;
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.