0
votes

in my webpage i have a gridview and im already setting each row's fore and backcolor if a certain element is present as shown in this code

 Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then
    Dim row As TableRow = e.Row
    Dim estado As String = (e.Row.Cells(6).Text).ToString

    If estado = "" Or estado = "Indefinido" Then
        row.BackColor = Color.White
        row.ForeColor = Color.Black
    ElseIf estado = "Presenças" Then
        row.BackColor = Color.LightGreen
        row.ForeColor = Color.Black
    ElseIf estado = "Falta" Then
        row.ForeColor = Color.Red

    ElseIf estado = "Suspenso" Then
        row.BackColor = Color.LightGray
        row.ForeColor = Color.DarkGray
    ElseIf estado = "Cancelado" Then
        row.BackColor = Color.Red
        row.ForeColor = Color.Black
    ElseIf estado = "Efectuado" Then
        row.BackColor = Color.White
        row.ForeColor = Color.Green
    End If

End If
End Sub

so my problem starts when im trying to change the selected row backcolor, so what i wanted was like when i select a row the backcolor goes blue and the forecolor white, but the rows that already have a back-color for instance the estado = "Cancelado" that already has its back color set to red, when selected, the row back color stays red even though the border changes. here is the asp.net code that changes the selected row color border and fore color:

   <asp:GridView ID="dgvMarcacoes" runat="server" OnRowDataBound = "OnRowDataBound"  style="width:100%" AutoGenerateSelectButton="True">
        <SelectedRowStyle  ForeColor="White" BorderColor="#6666FF" BorderStyle="Solid" BackColor="#6666FF" />
    </asp:GridView>

So does anyone knows how can i make like the selected backcolor override the already set color ?thanks

1

1 Answers

0
votes

You are using OnRowDataBound, which may not be called again unless you are explicitly calling dgvMarcacoes.DataBind() or have made a change to the underlying data.

The best place to do final formatting is to override Render() and make any changes prior to calling the base class Render().

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    ' Make final changes here

    MyBase.Render(writer)
End Sub