【发布时间】:2014-04-09 16:18:52
【问题描述】:
我这辈子都想不通...我有一个附加了 sqldatasource 的 gridview,我在 editItemtemplate 中格式化了 fee_amt 像这样。当通过单击更新 lnk 按钮引发 OnRowUpdating 事件时,我收到此错误。另请注意,我将文本框中的数字格式化为“$”,例如“$200.00”。
我很确定问题出在 fee_amt 但我可能错了。
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) +9592843
System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +146
System.Convert.ToDecimal(String value, IFormatProvider provider) +67
System.String.System.IConvertible.ToDecimal(IFormatProvider provider) +10
System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +491
System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +126
System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +63
System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +550
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +346
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +95
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1226
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +855
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +121
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Protected Sub OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridViewDegfaultCharges.RowUpdating
'OnRowUpdating Sets Update Params for the GridView
Dim TextBox2 As TextBox 'category
Dim TextBox3 As TextBox 'fee_name
Dim TextBox4 As TextBox 'fee_amt
Dim CheckBox1 As CheckBox 'inactive
Dim blnValid As Boolean
lblMessage.Text = ""
blnValid = True
TextBox2 = GridViewDegfaultCharges.Rows(e.RowIndex).FindControl("TextBox2")
TextBox3 = GridViewDegfaultCharges.Rows(e.RowIndex).FindControl("TextBox3")
TextBox4 = GridViewDegfaultCharges.Rows(e.RowIndex).FindControl("TextBox4")
CheckBox1 = GridViewDegfaultCharges.Rows(e.RowIndex).FindControl("CheckBox1")
If CheckDefaultChargesCategory(TextBox2.Text) Then
lblMessage.Text = TextBox2.Text & " is not a valid Loan Type"
blnValid = False
e.Cancel = True
Exit Sub
End If
SqlDataDefaultCharges.UpdateParameters("category").DefaultValue = TextBox2.Text
SqlDataDefaultCharges.UpdateParameters("fee_name").DefaultValue = TextBox3.Text
SqlDataDefaultCharges.UpdateParameters("fee_amt").DefaultValue = Convert.ToDecimal(TextBox4.Text).ToString()
SqlDataDefaultCharges.UpdateParameters("investorID").DefaultValue = Convert.ToInt32(_pageID)
SqlDataDefaultCharges.UpdateParameters("inactive").DefaultValue = CheckBox1.Checked
If blnValid Then
SqlDataDefaultCharges.Update()
End If
End Sub
【问题讨论】:
-
尝试去掉$符号
-
似乎仍然不想工作...实际 aspx 文件上的参数字段值类型是小数。不确定这是否有帮助。
-
这意味着 200 不是被保存的值。它是 '$200' 或不能转换为数字的空字符串(null)