Hello
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 .
<asp:LinkButton ID="LinkButton1" runat="server" Text="Add To Cart" CommandName="addtocart" CommandArgument='<%# Eval("id")%>' >
when the user click the linkbutton this event fire:
protected void theDataList_ItemCommand(object source, DataListCommandEventArgs e)
{
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;
}
after that when the user click the button which It's text is "show shopping cart",
the user will see the shoppingcart.aspx page
Response.Redirect("shoppingcart.aspx");
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:
<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="7" Name="cart" SessionField="cart"
Type="Int32" />
</SelectParameters>
I dont know how to solve it if any body help me I become so Thankful.