i am getting this error whenever i am pressing the addcart button.
products.aspx
<asp:SqlDataSource ID="SqlDataSource1? runat="server" ConnectionString=" ConnectionStrings:prdcts_accsrsConnectionString1" SelectCommand="SELECT [ProductID], [Name], [Description], [Price], [ImagePath] FROM [Products]">
</div>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="4"
RepeatDirection="Horizontal">
<itemstyle cssclass="box" />
<itemtemplate>
<div style="height:320px; width:220px; background:white; padding:30px 0 0 30px">
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductID") %>' Visible="false" >
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("ImagePath" , "~/products/Accessories/Images\\{0}") %>' PostBackUrl='<%# Eval("ProductID", "ProductDetails.aspx?ProductID={0}") %>' Height="170px" Width="180px" /><br /></td></tr>
<asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImagePath", "~/products/Accessories/Images\\{0}") %>' Visible="False"><br />
<tr> <td class="td"> <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'><br /></td></tr>
<tr> <td class="td"> <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:##0.00}") %>'><br /></td></tr>
<tr><td style="padding:15px 0 0 0">
<div style="float:left">
<asp:Button ID="Button1" runat="server" Text="Add To Cart" CssClass="bttn"
onclick="Button1_Click"/> </div>
<div style="float:right; padding-removed30px; margin-removed-10px"> <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/products/TransparentHeart.png" Height="50px" Width="50px"/></div></td></tr>
</table>
</div>
</itemtemplate>
<br />
<asp:HyperLink ID="CartLink" runat="server" NavigateUrl="~/UserCart.aspx">View Shopping Cart<br />
<br />
<br />
products.aspx.cs
public partial class Products_Accessories_Products : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
double Price = double.Parse(((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text);
string ProductName = ((Label)DataList1.Controls[0].FindControl("NameLabel")).Text;
string ProductImageUrl = ((Label)DataList1.Controls[0].FindControl("ImageUrlLabel")).Text;
int ProductID = int.Parse(((Label)DataList1.Controls[0].FindControl("ProductID")).Text);
if (Profile.SCart == null)
{
Profile.SCart = new ShoppingCartExample.Cart();
}
Profile.SCart.Insert(ProductID, Price, 1, ProductName, ProductImageUrl);
Server.Transfer("~/products/Accessories/Products.aspx");
}
}
What Should I do? I am getting this error in this line:
int ProductID = int.Parse(((Label)DataList1.Controls[0].FindControl("ProductID")).Text);