HelpfulChad
New Member
I want to create an online store web site.I have created a datalist which shows my products in my site, I put the LinkButton in my datalist for getting the productID of the product which the user select and add it to shopping cart.\[code\] <asp:LinkButton ID="LinkButton1" runat="server" Text="Add To Cart" CommandName="addtocart" CommandArgument='<%# Eval("id")%>' >\[/code\]When the user click the linkbutton this event fires:\[code\]protected void theDataList_ItemCommand(object source, DataListCommandEventArgs e){//this add the selected product-id to the list<int> and put it in the // session["addtocart"] if (e.CommandName == "addtocart") { int productid = Convert.ToInt32(e.CommandArgument); Label6.Text = productid.ToString(); List<int> productsincart = (List<int>)Session["addtocart"]; if (productsincart == null) { productsincart = new List<int>(); } productsincart.Add(productid); Session["addtocart"] = productsincart;} \[/code\]After that when the user click the button which It's text is "show shopping cart",the user will see the shoppingcart.aspx page\[code\] Response.Redirect("shoppingcart.aspx");\[/code\]in this page I have a gridview and I want to bind it to session["addtocart"];when the page load the gridview show the selected products which their ids are in the session["cart"]but it does not work and this error happened:System.InvalidCastException: Object must implement IConvertible.this is the related code:\[code\] <asp:GridView ID="GridView3" runat="server" DataSourceID="SqlDataSource1" > <columns> <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" /> <asp:BoundField DataField="name" HeaderText="post" SortExpression="post" /> <asp:BoundField DataField="price" HeaderText="salary" SortExpression="salary" /> <asp:BoundField DataField="color" HeaderText="years" SortExpression="years" /> </columns> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:employeeConnectionString4 %>" SelectCommand="SELECT * FROM [products] WHERE ([productid] = @productid)"> <SelectParameters> <asp:SessionParameter DefaultValue="http://stackoverflow.com/questions/12762604/7" Name="cart" SessionField="cart" Type="Int32" /> </SelectParameters>\[/code\]I know the problem is related to the GridView3 and the Session["addtocart"],I Think the GridView3 can not convert the value from the Integer list object which is stored in the Session["addtocart"] to the Integer,It seems to me the error is coming from the conversion from the session object to the Integer List, but I Dont know how to solve this problem if any body help me I become so Thankful.