非常奇怪的“如果值> = x”错误 [英] Very odd "If value >= x" Error

查看:44
本文介绍了非常奇怪的“如果值> = x”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有gridview的页面,如果列中的

数字大于或等于45,则行显示不同的颜色。我也这样做了

旁边的列的条件格式。这是我的代码。

aspx文件中的


=================== ============

< asp:GridView ID =" gvData" RUNAT = QUOT;服务器" OnRowDataBound =" doColor">

===============================

aspx.vb文件中的


=========================== ====

Sub doColor(ByVal sender As Object,ByVal e As GridViewRowEventArgs)

如果e.Row.RowType = DataControlRowType.DataRow那么


如果e.Row.Cells(10).Text> =" 60"然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(10).ForeColor = Drawing.Color.Red

e.Row.Cells(10).Font.Bold = True

结束如果

如果e.Row.Cells(9).Text> =" 45 QUOT;然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


结束如果

End Sub

===============================


Cells(10)语句效果很好。只有那些大于或等于60的结果是粗体红色和黄色突出显示。


然而,在细胞(9)上,它是另一个故事。出于某种原因,每个

结果为5也是粗体红色突出显示。我尝试将代码

更改为:


如果e.Row.Cells(9).Text< =" 4"然后


并且5s不再是大胆的红色。事实上,如果我尝试其中任何一个


如果e.Row.Cells(9).Text> =" 9"然后

如果e.Row.Cells(9).Text> =" 8"然后

如果e.Row.Cells(9).Text> =" 7"然后

如果e.Row.Cells(9).Text> =" 6"然后


然后,如果单元格中的文本为5,则不是粗体红色。一旦我输入

两位数,就像这样..


如果e.Row.Cells(9).Text> =" 10"


然后数字5变为粗体红色。它应该只是大胆的红色,如果是10

或更高!


我也试过这个,这很好用;数字5(或任何其他数字)

不是粗体红色,只有数字55 ......


如果是e.Row.Cells(9 ).Text> =" 55"

我知道我正在尝试对文本进行数值条件,这似乎有效。

无论如何10.为了测试它,我尝试在测试之前将

文本的值转换为整数,就像这样,


如果是CInt( e.Row.Cells(9).Text)> =" 10"


这只返回一个错误,我找不到任何其他转换方式

将文本转换成整数来进行条件检查。


关于这个奇怪错误的任何想法?这非常令人沮丧。


TIA,

Jim

解决方案

嗨吉姆,


你不会通过执行文本比较来获得你想要的结果,就好像它们是数字一样。


你指定了你试图转换数字,但它失败,可能是由于无效或空数据。要避免

转换错误,请首先检查Text属性是否可以转换为整数。如果您正在使用2.0框架,您可以使用

Int32.TryParse,否则您可以捕获异常。


-

Dave Sexton


吉姆在亚利桑那州 < ti ******* @ hotmail.comwrote in message news:uG ************** @ TK2MSFTNGP06.phx.gbl ...


>我创建了一个带有gridview的页面,如果列中的数字大于或等于45,则行显示不同的颜色。我还为这个条件格式设置了它旁边的列。这是我的代码。

aspx文件中的


=================== ============

< asp:GridView ID =" gvData" RUNAT = QUOT;服务器" OnRowDataBound =" doColor">

===============================

aspx.vb文件中的


=========================== ====

Sub doColor(ByVal sender As Object,ByVal e As GridViewRowEventArgs)

如果e.Row.RowType = DataControlRowType.DataRow那么


如果e.Row.Cells(10).Text> =" 60"然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(10).ForeColor = Drawing.Color.Red

e.Row.Cells(10).Font.Bold = True

结束如果

如果e.Row.Cells(9).Text> =" 45 QUOT;然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


结束如果

End Sub

===============================


Cells(10)语句效果很好。只有那些大于或等于60的结果用粗体红色表示黄色

高亮。


然而,在单元格(9)上,它是另一个故事。出于某种原因,每个5的结果都是粗体红色突出显示。我尝试将
更改为此代码:



并且5s不再是大胆的红色。事实上,如果我尝试其中任何一个


如果e.Row.Cells(9).Text> =" 9"然后

如果e.Row.Cells(9).Text> =" 8"然后

如果e.Row.Cells(9).Text> =" 7"然后

如果e.Row.Cells(9).Text> =" 6"然后


然后,如果单元格中的文本为5,则不是粗体红色。一旦我输入两位数,就像这样..


如果e.Row.Cells(9).Text> =" 10"


然后数字5变为粗体红色。如果它是10或更大,它应该只是大胆的红色!


我也试过这个,这很好用;数字5(或任何其他数字)不是粗体红色,只有数字55 ......

如果e.Row.Cells(9).Text> =" 55


我知道我正在尝试对文本进行数值条件,这对于单元格10来说似乎无论如何。只是为了测试它,我试图转换

测试前整数文本的值,如此,


如果CInt(e.Row.Cells(9).Text)> =" 10


这只返回一个错误,我找不到任何其他方法将文本转换为整数来进行条件检查。


关于这个奇怪错误的任何想法?非常令人沮丧。


TIA,

Jim



Dave Sexton写道:


嗨Jim,


你不会通过表演得到你想要的结果文本比较,好像它们是数字一样。


您指定您尝试转换数字但它失败了,可能是由于无效或空数据。要避免

转换错误,请首先检查Text属性是否可以转换为整数。如果您正在使用2.0框架,您可以使用

Int32.TryParse,否则您可以捕获异常。



我做了尝试:


如果Int32.TryParse(e.Row.Cells(9).Text)> =" 45"然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


但是当我做蓝线时出现在线下错误:

重载解析失败,因为没有可访问的''TryParse'接受这个

的参数。


当然,我试过没有显示Visual Studio IDE错误:


如果CInt(e.Row.Cells(9).Text)> = 45那么

e.Row.BackColor = Drawing.Color.LightYellow

e。 Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


但是当我运行页面时出现这个错误:

======================= ===================


其中一个标识的项目格式无效。

描述:执行

当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取更多信息

有关错误及其在代码中的起源。


异常详细信息:System.FormatException:已确定之一物品

的格式无效。


来源错误:

第8行:如果e.Row.RowType = DataControlRowType。 DataRow然后

第9行:

第10行:如果CInt(e.Row.Cells(10).Text)> = 60那么

第11行:e.Row.BackColor = Drawing.Color.LightYellow

第12行:

================ ==========================


我正在使用2.0框架和VS2005标准。


我不知道该做什么。任何人,任何人?


嗨Jim,


第一个错误(蓝线)清楚地表明你没有指定TryParse方法的所有必需参数。


MSDN上的Int32.TryParse:
http://msdn2.microsoft.com/en-us/library/f02979c7.aspx


发生第二个错误FormatException,因为单元格的Text属性没有返回一个可以转换为整数的值。正如我在上一篇文章中所说,如果你愿意,你可以捕获FormatException,但我认为TryParse是更好的选择。


-

Dave Sexton


吉姆在亚利桑那州 < ti ******* @ hotmail.comwrote in message news:%2 **************** @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
Dave Sexton写道:


>嗨吉姆,

你不会去通过执行文本比较来获得您想要的结果,就好像它们是数字一样。

您指定您尝试转换数字但它失败,可能是由于无效或空数据。要避免
转换错误,请首先检查Text属性是否可以转换为整数。如果您正在使用2.0框架,您可以使用
Int32.TryParse,否则您可以捕获异常。



我尝试过:


如果Int32.TryParse(e.Row.Cells(9).Text)> =" 45"然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


但是当我做蓝线时出现在线下错误:

重载解析失败,因为没有可访问的''TryParse'接受这个数量的论点。


当然,我试过没有显示Visual Studio IDE错误:


如果是CInt(e.Row) .Cells(9).Text)> = 45然后

e.Row.BackColor = Drawing.Color.LightYellow

e.Row.Cells(9).ForeColor = Drawing.Color.Red

e.Row.Cells(9).Font.Bold = True

结束如果


但是当我运行页面时出现此错误:

=============================== ===========


其中一个标识的项目格式无效。

描述:期间发生了未处理的异常执行当前的Web请求。请查看堆栈跟踪

有关错误的更多信息及其在代码中的起源。


异常详细信息:System.FormatException:已确定其中一个项目格式无效。


来源错误:


第8行:如果e.Row.RowType = DataControlRowType.DataRow则

第9行:

第10行:如果CInt(e.Row.Cells(10).Text)> = 60那么

第11行: e.Row.BackColor = Drawing.Color.LightYellow

第12行:

==================== ======================


我正在使用2.0框架和VS2005标准。


我不知道该做什么。任何人,任何人?



I made a page with a gridview that has rows show a different color if a
number in a column is greater than or equal to 45. I also did this
conditional formatting for the column next to it. Here''s my code.

in the aspx file
===============================
<asp:GridView ID="gvData" runat="server" OnRowDataBound="doColor">
===============================

in the aspx.vb file
===============================
Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then

If e.Row.Cells(10).Text >= "60" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(10).ForeColor = Drawing.Color.Red
e.Row.Cells(10).Font.Bold = True
End If
If e.Row.Cells(9).Text >= "45" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

End If
End Sub
===============================

The Cells(10) statement works great. Only those results that are greater
than or equal to 60 are in bold red with yellow highlight.

On the Cells(9), however, its another story. For some reason, every
result that is 5 is also bold red highlighted. I tried changing the code
to this:

If e.Row.Cells(9).Text <= "4" Then

And the 5s are no longer in bold red. In fact, if I try any of these

If e.Row.Cells(9).Text >= "9" Then
If e.Row.Cells(9).Text >= "8" Then
If e.Row.Cells(9).Text >= "7" Then
If e.Row.Cells(9).Text >= "6" Then

Then if the text in the cell is 5 it is not in bold red. Once I put in
two digits, like so ..

If e.Row.Cells(9).Text >= "10"

Then the number 5 turns bold red. It should only be bold red if it is 10
or greater!

I also tried this, which works fine; the number 5 (or any other number)
is not in bold red, only the number 55 ...

If e.Row.Cells(9).Text >= "55"

I know i''m trying to do numerical conditions on text, which seem to work
anyway for cell 10. Just to test it, I tried to convert the value of the
text to an integer before the test, like so,

If CInt(e.Row.Cells(9).Text) >= "10"

This only returned an error and I couldn''t find any other way to convert
the text into an integer to do the condition check.

Any ideas on this strange error? Its very frustrating.

TIA,
Jim

解决方案

Hi Jim,

You''re not going to get the results that you desire by performing textual comparisons as if they are numeric.

You specified that you tried to convert the number but that it is failing, probably due to invalid or null data. To avoid the
conversion error first check if the Text property can be converted to an integer. If you''re using the 2.0 framework you can use
Int32.TryParse, otherwise you can just catch the exception.

--
Dave Sexton

"Jim in Arizona" <ti*******@hotmail.comwrote in message news:uG**************@TK2MSFTNGP06.phx.gbl...

>I made a page with a gridview that has rows show a different color if a number in a column is greater than or equal to 45. I also
did this conditional formatting for the column next to it. Here''s my code.

in the aspx file
===============================
<asp:GridView ID="gvData" runat="server" OnRowDataBound="doColor">
===============================

in the aspx.vb file
===============================
Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then

If e.Row.Cells(10).Text >= "60" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(10).ForeColor = Drawing.Color.Red
e.Row.Cells(10).Font.Bold = True
End If
If e.Row.Cells(9).Text >= "45" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

End If
End Sub
===============================

The Cells(10) statement works great. Only those results that are greater than or equal to 60 are in bold red with yellow
highlight.

On the Cells(9), however, its another story. For some reason, every result that is 5 is also bold red highlighted. I tried
changing the code to this:

If e.Row.Cells(9).Text <= "4" Then

And the 5s are no longer in bold red. In fact, if I try any of these

If e.Row.Cells(9).Text >= "9" Then
If e.Row.Cells(9).Text >= "8" Then
If e.Row.Cells(9).Text >= "7" Then
If e.Row.Cells(9).Text >= "6" Then

Then if the text in the cell is 5 it is not in bold red. Once I put in two digits, like so ..

If e.Row.Cells(9).Text >= "10"

Then the number 5 turns bold red. It should only be bold red if it is 10 or greater!

I also tried this, which works fine; the number 5 (or any other number) is not in bold red, only the number 55 ...

If e.Row.Cells(9).Text >= "55"

I know i''m trying to do numerical conditions on text, which seem to work anyway for cell 10. Just to test it, I tried to convert
the value of the text to an integer before the test, like so,

If CInt(e.Row.Cells(9).Text) >= "10"

This only returned an error and I couldn''t find any other way to convert the text into an integer to do the condition check.

Any ideas on this strange error? Its very frustrating.

TIA,
Jim



Dave Sexton wrote:

Hi Jim,

You''re not going to get the results that you desire by performing textual comparisons as if they are numeric.

You specified that you tried to convert the number but that it is failing, probably due to invalid or null data. To avoid the
conversion error first check if the Text property can be converted to an integer. If you''re using the 2.0 framework you can use
Int32.TryParse, otherwise you can just catch the exception.

I did try:

If Int32.TryParse(e.Row.Cells(9).Text) >= "45" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

But when I do a blue line shows up under the line with the error:
Overload resolution failed because no accessible ''TryParse" accepts this
number of arguments.

Of course, I tried this with no Visual Studio IDE errors shown:

If CInt(e.Row.Cells(9).Text) >= 45 Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

But I get this error when I run the page:
==========================================

One of the identified items was in an invalid 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: One of the identified items
was in an invalid format.

Source Error:
Line 8: If e.Row.RowType = DataControlRowType.DataRow Then
Line 9:
Line 10: If CInt(e.Row.Cells(10).Text) >= 60 Then
Line 11: e.Row.BackColor = Drawing.Color.LightYellow
Line 12:
==========================================

I am using the 2.0 framework and VS2005 Standard.

I don''t know what to do at this point. Anyone, Anyone?


Hi Jim,

The first error (blue line) clearly states that you haven''t specified all of the required arguments for the TryParse method.

Int32.TryParse on MSDN:
http://msdn2.microsoft.com/en-us/library/f02979c7.aspx

The second error, FormatException, occurs because the Text property of the cell is not returning a value that can be converted into
an integer. As I said in my previous post, you can catch the FormatException if you want, but I think TryParse is the better
choice.

--
Dave Sexton

"Jim in Arizona" <ti*******@hotmail.comwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...

Dave Sexton wrote:

>Hi Jim,

You''re not going to get the results that you desire by performing textual comparisons as if they are numeric.

You specified that you tried to convert the number but that it is failing, probably due to invalid or null data. To avoid the
conversion error first check if the Text property can be converted to an integer. If you''re using the 2.0 framework you can use
Int32.TryParse, otherwise you can just catch the exception.


I did try:

If Int32.TryParse(e.Row.Cells(9).Text) >= "45" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

But when I do a blue line shows up under the line with the error:
Overload resolution failed because no accessible ''TryParse" accepts this number of arguments.

Of course, I tried this with no Visual Studio IDE errors shown:

If CInt(e.Row.Cells(9).Text) >= 45 Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

But I get this error when I run the page:
==========================================

One of the identified items was in an invalid 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: One of the identified items was in an invalid format.

Source Error:
Line 8: If e.Row.RowType = DataControlRowType.DataRow Then
Line 9:
Line 10: If CInt(e.Row.Cells(10).Text) >= 60 Then
Line 11: e.Row.BackColor = Drawing.Color.LightYellow
Line 12:
==========================================

I am using the 2.0 framework and VS2005 Standard.

I don''t know what to do at this point. Anyone, Anyone?



这篇关于非常奇怪的“如果值&gt; = x”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆