0
我試圖在滿足某些條件時更改.Net GridView
的backcolor
。這應該是相當簡單的,但顏色變化沒有發生。檢查呈現的HTML在受影響的行中顯示完全沒有任何不同,即使鏈接上的文本更改按預期發生。GridView的主題是否阻止對RowDataBound上行的backcolor屬性的更改
對於所有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
得到相同的結果。