I want to make all of the cell have their own color
eg,
This is the code of that situation
Protected Sub gvMonthlyReport_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Header Then
e.Row.CssClass = "HeaderRow"
e.Row.HorizontalAlign = HorizontalAlign.Center
e.Row.VerticalAlign = VerticalAlign.Middle
End If
'If e.Row.RowType = DataControlRowType.DataRow Then
' e.Row.CssClass = "cellRow"
'End If
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(17)
Dim status As String = cell.Text
If status = "v" Then
cell.BackColor = Color.Yellow
ElseIf status = "H" Then
cell.BackColor = Color.Blue
ElseIf status = "P.H" Then
cell.BackColor = Color.Green
Else
cell.BackColor = Color.Red
End If
End If
End Sub
this code i have done give me the output color only one column like this image
actually i want all column , can someone show me?
You have hardcoded cell number 17, but you need to use a loop in the RowDataBound event.
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim i As Integer = 0
Do While (i < e.Row.Cells.Count)
Dim cell As TableCell = CType(e.Row.Cells(i),TableCell)
cell.BackColor = Color.Red
i = (i + 1)
Loop
End If