单选按钮列表项始终为 false

发布于 2024-07-25 19:35:22 字数 1563 浏览 2 评论 0原文

我希望你能帮忙。 这让我困惑了好几个小时。

我的 CustomerGroupConfirm.aspx 页面中有一个 RadioButton 列表:

<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>

我选择一个 RadioButton,当我单击“确认默认客户合同组”按钮时,这里是代码隐藏中触发的函数:

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");
}

问题是列表项 (li .Selected) 始终为 false。

我究竟做错了什么? 任何人都可以帮忙吗?

亲切的问候

沃尔特

I hope you can help. This has been confounding me for hours.

I have a RadioButton list in my CustomerGroupConfirm.aspx page:

<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>

I select a RadioButton and when I click on the button "Confirm Default Customer Contract Group" here is the function in code-behind which fires:

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");
}

The problem is that the List Item (li.Selected) is always false.

What am I doing wrong? Can anyone help please.

Kind Regards

Walter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霊感 2024-08-01 19:35:22

也许您在每次回发中都绑定了 rblContractGroups 单选按钮列表。 您应该将其放入 IsPostBack 控件中:

if (!Page.IsPostBack)
{
    // Bind your rblContractGroups
}

Maybe you're binding your rblContractGroups radiobuttonlist in every postback. You should put it into IsPostBack control :

if (!Page.IsPostBack)
{
    // Bind your rblContractGroups
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文