0

I have a grid with few rows. On satisying a certain condition, I need to change the background color of the row that satifies that condition. I do this in the rowdatabound event of the grid, but then it loses the color during the page postback. How do I fix this issue? My code is like so.

If (e.Row.RowType = DataControlRowType.DataRow) Then
    Dim lblShowBreak As System.Web.UI.WebControls.Label = e.row.FindControl("lblShowBreak")
    Dim lblIsBreak As System.Web.UI.WebControls.Label = e.row.FindControl("lblIsBreak")

    If Trim(lblIsBreak.Text) = "Y" Then
       e.Row.BackColor = System.Drawing.Color.Black
    End If
End If
4

3 回答 3

0

I think, you can mark e.Row.BackColor = System.Drawing.Color.Black in the OnPreRender method every time. In this case state will be saved always.

于 2013-05-14T04:37:16.627 回答
0

You have to use RowDataBound event of Grid View like

Protected Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
     If `set your condition here` Then
     e.Row.BackColor = System.Drawing.Color.Black
End If
     End If
End Sub

You have to use something like that.

Hope You understand and works for you.

于 2013-05-14T04:41:59.723 回答
0

I have resolved this..my fix is as follows.

If Trim(lblIsBreak.Text) = "Y" Then
   lblShowBreak.Visible = True
   For i = 0 To gvTimeTable.Columns.Count - 1
       e.Row.Cells(i).BackColor = System.Drawing.Color.LightGray
   Next
End If
于 2013-05-14T07:16:49.633 回答