未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 70: int gridviewQuantity = Convert.ToInt16(GridViewShoppingCartList.DataKeys[i].Value);//int.Parse(GridViewShoppingCartList.Rows[i].Cells[3].Text);
行 71: //if textboxquantity is changed and checkedRemove is checked!
行 72: if( quantity!=gridviewQuantity||checkBoxRemove.Checked==true)
行 73: {
行 74: Label labelBookId = (Label)GridViewShoppingCartList.Rows[i].FindControl("LabelBookId");
源文件: f:\MyOnNetBookSell\ShoppingCarts.aspx.cs 行: 72以下是代码: protected void UpdateShoppingCartList()
{
ShoppingCart cart = new ShoppingCart();
//obtain current user's shopping cart id
string cartId = cart.GetShoppingCartID();
//itarate through all rows with the shopping cart
for (int i = 0; i < GridViewShoppingCartList.Rows.Count;i++ )
{
//
TextBox textBoxQuantity = (TextBox)GridViewShoppingCartList.Rows[i].FindControl("TextBoxQuantity");
CheckBox checkBoxRemove = (CheckBox)GridViewShoppingCartList.Rows[i].FindControl("TextBoxRemove");
int quantity;
//try
//{
quantity = int.Parse(textBoxQuantity.Text);
int gridviewQuantity = Convert.ToInt16(GridViewShoppingCartList.DataKeys[i].Value);//int.Parse(GridViewShoppingCartList.Rows[i].Cells[3].Text);
//if textboxquantity is changed and checkedRemove is checked!
if( quantity!=gridviewQuantity||checkBoxRemove.Checked==true)
{
Label labelBookId = (Label)GridViewShoppingCartList.Rows[i].FindControl("LabelBookId");
if (quantity == 0 || checkBoxRemove.Checked == true)//运行到这里就报上面那个错
{
cart.RemoveItems(cartId,Int32.Parse(labelBookId.Text));
}
else
{
cart.UpdateItems(cartId,Int32.Parse(labelBookId.Text),quantity);
}
}
//}
//catch
//{
// LabelError.Visible = true;
// LabelError.Text = "There has been a problem with one or more of your inputs.";
//} }
}
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 70: int gridviewQuantity = Convert.ToInt16(GridViewShoppingCartList.DataKeys[i].Value);//int.Parse(GridViewShoppingCartList.Rows[i].Cells[3].Text);
行 71: //if textboxquantity is changed and checkedRemove is checked!
行 72: if( quantity!=gridviewQuantity||checkBoxRemove.Checked==true)
行 73: {
行 74: Label labelBookId = (Label)GridViewShoppingCartList.Rows[i].FindControl("LabelBookId");
源文件: f:\MyOnNetBookSell\ShoppingCarts.aspx.cs 行: 72以下是代码: protected void UpdateShoppingCartList()
{
ShoppingCart cart = new ShoppingCart();
//obtain current user's shopping cart id
string cartId = cart.GetShoppingCartID();
//itarate through all rows with the shopping cart
for (int i = 0; i < GridViewShoppingCartList.Rows.Count;i++ )
{
//
TextBox textBoxQuantity = (TextBox)GridViewShoppingCartList.Rows[i].FindControl("TextBoxQuantity");
CheckBox checkBoxRemove = (CheckBox)GridViewShoppingCartList.Rows[i].FindControl("TextBoxRemove");
int quantity;
//try
//{
quantity = int.Parse(textBoxQuantity.Text);
int gridviewQuantity = Convert.ToInt16(GridViewShoppingCartList.DataKeys[i].Value);//int.Parse(GridViewShoppingCartList.Rows[i].Cells[3].Text);
//if textboxquantity is changed and checkedRemove is checked!
if( quantity!=gridviewQuantity||checkBoxRemove.Checked==true)
{
Label labelBookId = (Label)GridViewShoppingCartList.Rows[i].FindControl("LabelBookId");
if (quantity == 0 || checkBoxRemove.Checked == true)//运行到这里就报上面那个错
{
cart.RemoveItems(cartId,Int32.Parse(labelBookId.Text));
}
else
{
cart.UpdateItems(cartId,Int32.Parse(labelBookId.Text),quantity);
}
}
//}
//catch
//{
// LabelError.Visible = true;
// LabelError.Text = "There has been a problem with one or more of your inputs.";
//} }
}
没有找到复选框.!
{
ShoppingCart cart = new ShoppingCart();
//obtain current user's shopping cart id
string cartId = cart.GetShoppingCartID();
//itarate through all rows with the shopping cart
for (int i = 0; i < GridViewShoppingCartList.Rows.Count;i++ )
{ GridViewRow dvr = GridViewShoppingCartList.Rows[i]; //Insus.NET添加此句 if (dvr.FindControl("TextBoxQuantity") != null && dvr.FindControl("TextBoxRemove") != null) //Insus.NET更改此句
{
TextBox textBoxQuantity = (TextBox)dvr.FindControl("TextBoxQuantity"); //Insus.NET更改此句
CheckBox checkBoxRemove = (CheckBox)dvr.FindControl("TextBoxRemove");//Insus.NET更改此句
int quantity;
//try
//{
quantity = int.Parse(textBoxQuantity.Text);
int gridviewQuantity = Convert.ToInt16(GridViewShoppingCartList.DataKeys[i].Value);//int.Parse(dvr.Cells[3].Text);
//if textboxquantity is changed and checkedRemove is checked!
if (quantity != gridviewQuantity || checkBoxRemove.Checked == true)
{
Label labelBookId = (Label)dvr.FindControl("LabelBookId");//Insus.NET更改此句 if (quantity == 0 || checkBoxRemove.Checked)//Insus.NET更改此句
{
cart.RemoveItems(cartId, Int32.Parse(labelBookId.Text));
}
else
{
cart.UpdateItems(cartId, Int32.Parse(labelBookId.Text), quantity);
}
}
//}
//catch //{
// LabelError.Visible = true;
// LabelError.Text = "There has been a problem with one or more of your inputs.";
//}
}
}
}