I have a DataList Control as follows
<asp:DataList ID="DataList1" runat="server" DataKeyField="FruitID" RepeatColumns="2" Width="387px">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="104px" ImageUrl='<%# Eval("ImageUrl") %>' Width="135px" />
<br />
Item ID:
<asp:Label ID="lblItemID" runat="server" Text='<%# Eval("FruitID") %>' />
<br />
FruitName:
<asp:Label ID="lblFruitNameLabel" runat="server" Text='<%# Eval("FruitName") %>' />
<br />
UnitPrice:
<asp:Label ID="lblUnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />
<br />
Quantity:
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:Button ID="btnAddtoCart" runat="server" onclick="Button1_Click" Text="Add to Cart" />
and in the code behind im using the following code to get the values of the controls inside the DataList control
int id = int.Parse(((Label)DataList1.Controls[0].FindControl("lblItemID")).Text.ToString());
string Name = ((Label)DataList1.Controls[0].FindControl("lblFruitNameLabel")).Text;
double Price = double.Parse(((Label)DataList1.Controls[0].FindControl("lblUnitPriceLabel")).Text.ToString());
int Quantity = int.Parse(((TextBox)DataList1.Controls[0].FindControl("txtQuantity")).Text.ToString());
string Url = ((Image)DataList1.Controls[0].FindControl("Image1")).ImageUrl;
I'm getting the following exception
Input string was not in a correct format.
Exception occurs in the following line
int Quantity = int.Parse(((TextBox)DataList1.Controls[0].FindControl("txtQuantity")).Text.ToString());
I'm very much sure that i'm entering a Integer value to the textbox :)
am I missing something?