2014-12-05 84 views

回答

1

这可能是你正在寻找什么......虽然你将需要定制的东西,以适应你的程序的确切标准。我不认为你所有的领域都是整数,所以CInt可能会抛出异常。如果我知道GridView的布局是什么,我可以给你一个更具体的方法。

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound 

    If e.Row.RowType = DataControlRowType.DataRow Then 

     Dim max As Integer = e.Row.Cells.Count - 1 

     For i As Integer = 0 To max 

      Dim nbr As String = e.Row.Cells(i).Text.ToString 

      If Not Integer.TryParse(nbr, nbr) Then 

       nbr = "0" 

      End If 

      If CInt(nbr) > 10 Then 

       e.Row.Cells(i).BackColor = Drawing.Color.Red 

      End If 

     Next 

    End If 

End Sub 
+0

对不起,我忘了提。其中一列具有文本值。它会产生错误“从字符串”XYZ“转换为”整数“类型无效。我怎样才能胜过这个? – TheDProgrammer 2014-12-05 16:01:27

+0

对包含字符串/文本的字段提供了一种可能的解决方法。 – Zack 2014-12-05 20:31:31

相关问题