网格错误,请参阅
问题描述:
我希望使用值gridview保存会话,但无法保存
*我是定义函数;
请看.
i want value gridview to save Session but cant
* i am Definition function;
plaese see.
public string Add()
{
ArrayList arr;
if (Session["mycart"] != null)
{
arr = (ArrayList)Session["mycart"];
}
else
{
arr = new ArrayList();
Session["mycart"] = arr;
}
EmailTextBox.text = EmailGridView.rows(0).cells(1).text.ToString
CShoppingCartItem item = new CShoppingCartItem();
//item.ProductID = int.Parse(ReciveId);
//int.Parse(GridView1.Rows[0].Cells[2].Text.ToString());
<big> item.ProductName = GridView1.Rows[1].Cells[1].Text;</big>
.// item.Quantity = 1;
arr.Add(item);
return "s";
}
错误:
error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
答
是将网格视图绑定到arraylist. > 如果是,那么
Are You binding your gridview to arraylist.
if yes then
else
{
arr = new ArrayList();
Session["mycart"] = arr;
}
当您将arr存储到会话中之前,必须先初始化arraylist arr
when you store arr to session, before that you have to initialize arraylist arr
check the index of rows and cells. check if there is any value or not.
try 0 instead of 1 in 'rows[1]'.
like:-
GridView1.Rows[0].Cells[1].Text;