2009-06-27 64 views
1

我希望你能帮上忙。这让我困惑了好几个小时。单选按钮列表项总是虚假的

我有一个单选按钮列表在我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> 

我选择一个单选按钮,当我点击按钮“确认默认客户合同集团”这里是函数代码隐藏其中大火:

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

问题是List Item(li.Selected)总是为false。

我在做什么错?任何人都可以请帮忙。

亲切的问候

沃尔特

回答

1

也许你结合你的rblContractGroups单选按钮列表中的每个回发。你应该把它放到IsPostBack控件中:

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

你是绝对正确的。非常感谢。 – 2009-06-27 20:39:56