Click here to Skip to main content
15,908,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want value gridview to save Session but cant
* i am Definition function;
plaese see.


C#
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:
SQL
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Posted
Updated 28-Mar-12 18:59pm
v3

Are You binding your gridview to arraylist.
if yes then

C#
else
{
arr = new ArrayList();
Session["mycart"] = arr;
}


when you store arr to session, before that you have to initialize arraylist arr
 
Share this answer
 
Comments
saeed1364 29-Mar-12 0:50am    
is shopingcart
arraylist type is session
save value grid to arraylist

if arraylist is null then new arryalist
saeed1364 29-Mar-12 0:58am    
error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
SQL
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;
 
Share this answer
 
Comments
saeed1364 29-Mar-12 6:55am    
dont work GridView1.Rows[0].Cells[1].Text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900