G
Guest
I'm trying to cast a String from a web forms textbox into an Int16 (see code
below), but it's not quite working. When I post the textbox with numbers (no
alpha chars) I get the following error in my web page:
Exception Details: System.FormatException: Input string was not in a correct
format.
String qty;
foreach (GridViewRow row in gridView1.Rows)
{
if (!String.IsNullOrEmpty(qty) || qty != "0")
{
qty = ((TextBox)row.FindControl("txtQuantity")).Text;
order.quantity = Int16.Parse(qty); // debugger stops on this line
// order.quantity is defined as an Int16
}
}
I don't understand why I'm getting a FormatException since I'm not using any
formatting. Is there another approach I should be taking to cast my textbox
value?
below), but it's not quite working. When I post the textbox with numbers (no
alpha chars) I get the following error in my web page:
Exception Details: System.FormatException: Input string was not in a correct
format.
String qty;
foreach (GridViewRow row in gridView1.Rows)
{
if (!String.IsNullOrEmpty(qty) || qty != "0")
{
qty = ((TextBox)row.FindControl("txtQuantity")).Text;
order.quantity = Int16.Parse(qty); // debugger stops on this line
// order.quantity is defined as an Int16
}
}
I don't understand why I'm getting a FormatException since I'm not using any
formatting. Is there another approach I should be taking to cast my textbox
value?