代码之家  ›  专栏  ›  技术社区  ›  Nick

具有GridView主题是否阻止对RowDataBound上的行BackColor属性进行更改?

  •  0
  • Nick  · 技术社区  · 16 年前

    我正试图改变 backcolor 在.net中 GridView 当满足一定条件时。这应该相当简单,但颜色变化不会发生。检查呈现的HTML在受影响的行中显示出完全不同的内容,即使链接上的文本发生了预期的更改。

    有一个默认的主题集 gridviews 我以前也没用过。这是为了阻止我动态地更改行的颜色,还是我遗漏了其他内容?

    我正在使用.NET 3.5并在代码中包含以下内容:

    Protected Sub gvPrevious_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvPrevious.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If currentCorrespondence.IsRetired Then //custom object, returning as expected
                Dim link As LinkButton = DirectCast(e.Row.Controls(4).Controls(2), LinkButton) 
                link.Text = "Reinstate" //default is "retire" - GV renders this as expected
                e.Row.BackColor = Drawing.Color.IndianRed //might as well not be here 
            End If
        End If
    End Sub
    

    从上面的代码中,当我进入浏览器并查看源代码时,我希望看到 <tr style="background-color: #CD5C5C;"> 对于受影响的行。相反,我看到 <tr> <tr class="AlternateRowStyle"> (如适用)。我完全看不出 BackColor 属性更改。

    我也尝试过使用 e.Row.CssClass 结果相同。

    1 回复  |  直到 13 年前
        1
  •  1
  •   Tom Halladay Amy B    16 年前

    尝试如下操作:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Select Case e.Row.RowState
            Case DataControlRowState.Normal
                CType(e.Row, GridViewRow).Style.Add("background", "#CD5C5C")
        End Select
    End Sub
    
    推荐文章