PDA

View Full Version : "Input String was not in correct form" Error?


Punkcrib
09-26-2007, 04:44 PM
Ok I have 2 pages that use the exact same technique to insert a new item into a dropdown list:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Me.DropDownList1.DataBind()
Me.DropDownList1.Items.Insert(0, "-- Select --")
End If
End Sub

This works fine on one page, and gives me the following error on another:

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2725283
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +293
System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls.Parameter.get_ParameterValue() +92
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +284
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +344
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1252
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +65
System.Web.UI.WebControls.ListControl.PerformSelect() +32
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +33
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +31
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4436



I've noticed that when I remove the "-- Select --" and replace it with "", it runs fine. Also when I replace it with New ListItem(). But it works fine on the other page with "-- Select --". What could be causing this error? I'll post the rest of the code if requested, but I've pretty much narrowed it down to that line.

Any Ideas?

nikkiH
10-03-2007, 03:51 PM
The stack trace looks like it's items that are being data bound causing the problem, not the insert of item 0.
Is that control databound?

Punkcrib
10-08-2007, 05:25 PM
Sure was. I forgot to remove the Select statement until after I insert the new line in the DDL.

Thanks!