2009-06-27 65 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