【问题标题】:Radio Button List Item is always false单选按钮列表项始终为 false
【发布时间】:2010-11-06 09:57:27
【问题描述】:

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

我的 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。

我做错了什么?谁能帮忙。

亲切的问候

沃尔特

【问题讨论】:

    标签: asp.net radio-button


    【解决方案1】:

    也许您在每次回发中都绑定了您的 rblContractGroups 单选按钮列表。你应该把它放到 IsPostBack 控件中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-29
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      相关资源
      最近更新 更多