I have just tried looping through the items in the datalist but need to get an output from the loop to input into my query which I cannot do.
All combinations of int.Parse() , convert.ToInt32() with .Text and .Value have been used. Everytime there is a FormatException. I seem to think I am not getting the textbox value I input. If anyone knows how to fix another way please post.
Description: An
unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 64:
Line 65:
Line 66: int Qty = int.Parse(dlProducts.Controls[0].FindControl("txtProductQty").Text); Line 67:
If the TextBox
Text is a non-numeric, the
conversion will fail and will show the error message. So please do a non-numeric checking before the conversion. for example:
TextBox box = (TextBox)dlProducts.Controls[0].FindControl("txtProductQty");
if (box != null)
{
string val = box.Text;
if (!string.IsNullOrEmpty(val))
{
int Qty = int.Parse(val);
}
}
Please mark the replies as answers if they help or unmark if not.
Feedback to us
adrianmcg
Member
8 Points
58 Posts
Re: Get integer variable from datalist textbox for entry into SQL
Nov 16, 2012 12:32 PM|LINK
It seems I have come to a dead end on this one.
I have just tried looping through the items in the datalist but need to get an output from the loop to input into my query which I cannot do.
All combinations of int.Parse() , convert.ToInt32() with .Text and .Value have been used. Everytime there is a FormatException. I seem to think I am not getting the textbox value I input. If anyone knows how to fix another way please post.
sarathi125
Star
13599 Points
2691 Posts
Re: Get integer variable from datalist textbox for entry into SQL
Nov 16, 2012 03:55 PM|LINK
Hi,
Try like this
int qty = int.parse(dlProducts.Controls[0].FindControl("txtProductQty").Text);
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
adrianmcg
Member
8 Points
58 Posts
Re: Get integer variable from datalist textbox for entry into SQL
Nov 17, 2012 10:30 AM|LINK
That doesnt work. FormatException was unhandled by user code again.
adrianmcg
Member
8 Points
58 Posts
Re: Get integer variable from datalist textbox for entry into SQL
Nov 17, 2012 10:39 AM|LINK
my error page is as follows.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 64: Line 65: Line 66: int Qty = int.Parse(dlProducts.Controls[0].FindControl("txtProductQty").Text); Line 67:Source File: C:\Users\Adrian\Documents\Web Page Programming\ShoppingCart\ShoppingCart\Default.aspx.cs Line: 66
Stack Trace:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: Get integer variable from datalist textbox for entry into SQL
Nov 19, 2012 09:06 AM|LINK
If the TextBox Text is a non-numeric, the conversion will fail and will show the error message. So please do a non-numeric checking before the conversion. for example:
TextBox box = (TextBox)dlProducts.Controls[0].FindControl("txtProductQty"); if (box != null) { string val = box.Text; if (!string.IsNullOrEmpty(val)) { int Qty = int.Parse(val); } }Feedback to us
Develop and promote your apps in Windows Store