I'm going to assume this is a GridView or DetailsView in ASP.NET.
You're running into a problem with "...And ("Certificate")...". Rather than the clunky CType(sender, GridView).DataKeys(e.Row.RowIndex).Values("Certificate") that you're using all over the place it would be better to Dim a local variable.
Another way of looking at it.Code:Protected Sub TestGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles TestGridView.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim cert = CType(sender, GridView).DataKeys(e.Row.RowIndex).Values("Certificate") If cert < 100000 Then e.Row.BackColor = Color.LightBlue ElseIf cert < 1000000 AndAlso cert > 100000 Then e.Row.BackColor = Color.LightGreen ElseIf cert < 10000000 AndAlso cert > 1000000 Then e.Row.BackColor = Color.LightYellow Else e.Row.BackColor = Color.Blue End If End If End Sub
Code:If e.Row.RowType = DataControlRowType.DataRow Then Dim cert As Long = CLng(DataBinder.Eval(e.Row.DataItem, "Certificate")) Select Case cert Case cert < 100000 e.Row.BackColor = Color.LightBlue Case cert < 1000000 AndAlso cert > 100000 e.Row.BackColor = Color.LightGreen Case cert < 10000000 AndAlso cert > 1000000 e.Row.BackColor = Color.LightYellow Case Else e.Row.BackColor = Color.Blue End Select End If




Reply With Quote