我希望你能提供帮助。这让我困惑了几个小时。
我的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。
我做错了什么?任何人都可以帮忙。
亲切的问候
沃尔特
答案 0 :(得分:1)
也许你在每次回发中绑定你的rblContractGroups radiobuttonlist。你应该将它放入IsPostBack控件:
if (!Page.IsPostBack)
{
// Bind your rblContractGroups
}