J
Jim in Arizona
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
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