Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 125: //var amt = ob.SingleOrDefault(t => t.Planname == ddlexp.SelectedItem.Text);
Line 126: // Session["error"] = null;
Line 127: list.Add(new CartItem() { Type = "R", ProductName = ddlexp.SelectedItem.Text, Amount =Convert.ToDecimal(ddlexp.SelectedValue) , visibility = true });
Line 128: if (chkcover.Checked)
Line 129: {
Posted

"Input string was not in a correct format."
Means what it says: the string value you are passing to Convert.ToDecimal is not recognisable as a Decimal number.

Check the content of the drop down list, and see what SelectedValue is returning in the debugger.
 
Share this answer
 
Comments
krishna97 24-Oct-13 2:46am    
droup downlist bind

DataTable dtf = new DataTable();
dt = SelectData();
DataView dv = dt.DefaultView;
dv.RowFilter = "Category='" + s + "'";
if (dv.Count > 0)
{
DataTable ddd = new DataTable();
ddd = dv.Table;
ddlexp.DataTextField = "Planname";
ddlexp.DataValueField = "Amount";
ddlexp.DataSource = dv.Table;
ddlexp.DataBind();
}
OriginalGriff 24-Oct-13 3:05am    
Does not mean that the value returned by SelectedValue is a numeric string: it could be null, it could be "1.2.3", it could be anything.
So check it in the debugger and see exactly what it is that you are trying to convert...
Convert.ToDecimal(ddlexp.SelectedValue)

here the selected values is in string format which cannot be converted to decimal make sure that it is not in string format
 
Share this answer
 
Comments
krishna97 24-Oct-13 2:50am    
decimal format

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900