此錯誤不斷彈出,我似乎無法弄清楚它來自哪裏。對象引用未設置爲對象的實例(int)
if (!IsPostBack)
{
DataTable LocalCart = new DataTable();
LocalCart = (DataTable)Session["cart"];
int LocalCartItemCount = (int) Session["CartItemCount"];
Decimal LocalCartAmount = (Decimal)Session["CartAmount"];
if (LocalCart.Rows.Count == 0)
{
titleLabel.Text = "Your shopping cart is empty!";
GridCart.Visible = false;
updateButton.Enabled = false;
checkoutButton.Enabled = false;
totalAmountLabel.Text = String.Format("{0:c}", 0);
}
else
{
GridCart.DataSource = LocalCart;
GridCart.DataBind();
titleLabel.Text = "These are the products in your shopping cart:";
GridCart.Visible = true;
updateButton.Enabled = true;
checkoutButton.Enabled = true;
totalAmountLabel.Text = String.Format("{0:c}", LocalCartAmount);
}
它的說法錯誤的是在這裏 - >int LocalCartItemCount = (int) Session["CartItemCount"];
如果Session [「CartItemCount」]爲空,這會給你一個對象引用錯誤。 – valverij
現在同樣的錯誤 - > int.TryParse(Session [「CartItemCount」]。ToString(),out LocalCartItemCount); –
好吧,讓我們一起去看看我的編輯。 – Smeegs