输入字符串的格式不正确,如何解决?请高手指示,谢谢!

liulisi88 2010-04-22 09:44:17
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.FormatException: 输入字符串的格式不正确。

源错误:


行 127: lblPrice = e.Item.FindControl("label2")
行 128: If e.CommandSource.commandname = "numAdd" Then
行 129: txtNum.Text = (CInt(txtNum.Text) + 1).ToString
行 130: ElseIf e.CommandSource.CommandName = "numSub" Then
行 131: If CInt(txtNum.Text) > 1 Then


源文件: E:\kk\public\shopcart.ascx.vb 行: 129

堆栈跟踪:


[FormatException: 输入字符串的格式不正确。]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66

[InvalidCastException: 从字符串“”到类型“Integer”的转换无效。]
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +246
public_shopcart.DataGrid1_ItemCommand(Object source, DataGridCommandEventArgs e) in E:\kk\public\shopcart.ascx.vb:129
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs e) +108
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +81
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


...全文
2397 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 sandy945 的回复:]
If e.CommandSource.commandname = "numAdd" Then
If IsNumeric(txtNum.Text) Then
txtNum.Text = (CInt(txtNum.Text) + 1).ToString
Else
'不能转换成数字,给出提示
End If

其余的参照这个改
[/Quote]
谢谢!!算可以。。呵呵
阿非 2010-04-22
  • 打赏
  • 举报
回复
If e.CommandSource.commandname = "numAdd" Then
If IsNumeric(txtNum.Text) Then
txtNum.Text = (CInt(txtNum.Text) + 1).ToString
Else
'不能转换成数字,给出提示
End If

其余的参照这个改
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
行128: If e.CommandSource.commandname = "numAdd" Then
行129: txtNum.Text = (IsNumeric CInt(txtNum.Text) + 1).ToString
行130: ElseIf e.CommandSource.CommandName = "numSub" Then
行131: If IsNumeric CInt(txtNum.Text) > 1 Then
行132: txtNum.Text = (IsNumeric CInt(txtNum.Text) - 1).ToString


是不是这样放呀?好像也是不行哦!!
阿非 2010-04-22
  • 打赏
  • 举报
回复
CInt(txtNum.Text)

在这句代码之前, 所有的
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sandy945 的回复:]
131 行 也是 txtNum.Text

你需要 使用 IsNumeric 判断 txtNum.Text
[/Quote]


把IsNumeric放在哪里的呀??
阿非 2010-04-22
  • 打赏
  • 举报
回复
131 行 也是 txtNum.Text

你需要 使用 IsNumeric 判断 txtNum.Text
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sandy945 的回复:]
先使用 IsNumeric 函数 判断是否可以转换为 数字

可以之后再转换,反之给出提示
[/Quote]

谢谢!!
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.FormatException: 输入字符串的格式不正确。

源错误:


行 129: txtNum.Text = (CInt(txtNum.Text) + 1).ToString
行 130: ElseIf e.CommandSource.CommandName = "numSub" Then
行 131: If CInt(txtNum.Text) > 1 Then
行 132: txtNum.Text = (CInt(txtNum.Text) - 1).ToString
行 133: End If


源文件: E:\kk\public\shopcart.ascx.vb 行: 131

堆栈跟踪:


[FormatException: 输入字符串的格式不正确。]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66

[InvalidCastException: 从字符串“”到类型“Integer”的转换无效。]
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +246
public_shopcart.DataGrid1_ItemCommand(Object source, DataGridCommandEventArgs e) in E:\kk\public\shopcart.ascx.vb:131
System.Web.UI.WebControls.DataGrid.OnItemCommand(DataGridCommandEventArgs e) +108
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +81
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


还有131行的也是输入字符串格式不正确!晕~~
阿非 2010-04-22
  • 打赏
  • 举报
回复
先使用 IsNumeric 函数 判断是否可以转换为 数字

可以之后再转换,反之给出提示
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sandy945 的回复:]
[InvalidCastException: 从字符串“”到类型“Integer”的转换无效。]

你的字符串是空串, 不能被转换成 Integer
[/Quote]

高手,能说明白点吗?怎样改??
liulisi88 2010-04-22
  • 打赏
  • 举报
回复
各位高手,那怎样改阿??小女子笨笨!!
zl_c 2010-04-22
  • 打赏
  • 举报
回复
txtNum.Text的值可能为“”,并不是预期的数字字符串。
阿非 2010-04-22
  • 打赏
  • 举报
回复
[InvalidCastException: 从字符串“”到类型“Integer”的转换无效。]

你的字符串是空串, 不能被转换成 Integer

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧