簡體   English   中英

如何更改DataGrid行的背景顏色?

[英]How to change the background color of a DataGrid row?

我有一個DataGrid,當我將鼠標懸停在上面時,我想更改整個行的背景顏色。

我嘗試使用e.Item.Attributes["onmouseover"] = "this.style.color='red'"; 但這只會更改行中文本的顏色。 我要突出顯示整行。 如何設置背景顏色以更改后面代碼中的DataGrid中的行?

Private Sub DataGridID_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGridID.ItemDataBound

    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

        ' Do the mouseover and mouseout javascript
        Dim oBGcolour As String

        If e.Item.ItemType = ListItemType.Item Then
            oBGcolour = Right(Hex(DataGridID.ItemStyle.BackColor.ToArgb()), 6)
        ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
            oBGcolour = Right(Hex(DataGridID.AlternatingItemStyle.BackColor.ToArgb()), 6)
        End If

        e.Item.Attributes.Add("onmouseover", "this.style.background='#cdcdcd';")
        e.Item.Attributes.Add("onmouseout", "this.style.background='#" & oBGcolour & "';")

    End If

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM