Pergunta

Eu espero que você pode ajudar. Este foi me confundindo por horas.

Eu tenho uma lista RadioButton na minha página CustomerGroupConfirm.aspx:

<div>
    <table>
        <tbody>
            <tr>
                <td nowrap="nowrap">
                    <asp:RadioButtonList ID="rblContractGroups" runat="server"></asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td nowrap="nowrap">
                <br />
                    <asp:Button ID="btnConfirmCustomerContractGroups" runat="server" OnClick="confirmCustomerContractGroups_Click" CssClass="Button" Text="Confirm Default Customer Contract Group" />
                </td>
            </tr>
        </tbody>
    </table>
</div>

Eu selecionar um RadioButton e quando eu clicar no botão "Confirmar Padrão Cliente Contrato Grupo" aqui é a função em code-behind que incêndios:

protected void confirmCustomerContractGroups_Click(object sender, EventArgs e)
{
    // Iterate through the Radio Button list.
    foreach (ListItem li in rblContractGroups.Items)
    {
        if (li.Selected)
        // If the Radio Button List Item (Customer Contract Group) is Selected.
        {
            // Set the Default Customer Contract Group of the Current User.
            CustomerAccess.SetDefaultCustomerContractGroup(Int32.Parse(Session["CustomerID"].ToString()), Int32.Parse(li.Value));
        }
    }
    Response.Redirect("~/Default.aspx");
}

O problema é que o item da lista (li.Selected) é sempre falsa.

O que estou fazendo de errado? Alguém pode ajudar por favor.

Atenciosamente

Walter

Foi útil?

Solução

Talvez você esteja vinculativo seus rblContractGroups RadioButtonList em cada nova postagem. Você deve colocá-lo em controle IsPostBack:

if (!Page.IsPostBack)
{
    // Bind your rblContractGroups
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top