The datatype of Price is int, but the one of
txtPrice.Text
is a string. You first have to parse
txtPrice.Text
to an int before you can store it in
product.Price
:
int price;
if (int.TryParse(txtPrice.Text, out price))
{
product.Price = price;
}
else
{
}
More information about
int.TryParse
:
MSDN - Int32.TryParse Method (System)[
^]