在我的收貨地址頁面上有兩個RadioButtonList ListItems(下面顯示的代碼)根據用戶輸入寫入數據庫true或false。Asp.Net RadioButtonList選擇的ListItem頁面上不能識別
用戶第一次選擇一個值並轉到結帳過程的下一步時,他們的發貨地址類型會正確存儲在數據庫中(true/false)。如果他們返回送貨地址頁面,請選擇相反的ListItem並轉到下一個結賬頁面,其更新的送貨類型在數據庫中不會更改。就好像ListItem不能識別用戶的單選按鈕選擇在重新訪問頁面時已經改變。
有人可以幫忙解決這個問題嗎?
ShippingAddress.ascx
<asp:RadioButtonList id="ShipToAddressType" runat="server">
<asp:ListItem Value="0" id="businessShipping">My shipping address is a business.</asp:ListItem>
<asp:ListItem Value="1" id="residenceShipping">My shipping address is a residence.</asp:ListItem>
</asp:RadioButtonList>
ShippingAddress.ascx.cs
if (residenceShipping.Selected == true)
shippingAddress.Residence = true;
else
shippingAddress.Residence = false;
ShippingAddress.ascx.cs的Page_Load
protected void Page_Load(object sender, EventArgs e)
{
User user = Token.Instance.User;
Address shipAddress = null;
foreach (Address tempAddress in user.Addresses) if (tempAddress.Nickname == "Shipping") shipAddress = tempAddress;
// sets radio button of return users previously selected ship type
if (shipAddress != null)
{
if (shipAddress.Residence == false)
{
ShipToAddressType.SelectedIndex = 0;
}
else
{
ShipToAddressType.SelectedIndex = 1;
}
}
}
該問題表明與頁面生命週期有關的誤解/錯誤。與給定的信息不能幫助! – humblelistener
可能需要更多信息...您的代碼隱藏中的PageLoad事件處理程序是什麼樣子的? – Brian
我編輯帖子,添加上面的頁面加載事件處理程序。謝謝! – Joe