要保留突出顯示行的原始顏色,以便在突出顯示不同行時返回原始顏色,請嘗試以下解決方案。
JavaScript的網頁上:
var lastStyle;
var lastRowID;
function highlightRow(rowID, updatedStyle) {
var rowClicked = document.getElementById(rowID);
restoreRowColor(lastRowID, lastStyle);
lastStyle = rowClicked.className;
lastRowID = rowID;
rowClicked.className = "highlightRow";
}
function restoreRowColor(rowID, originalStyle) {
var previousRowClicked = document.getElementById(rowID);
if (previousRowClicked != null) {
previousRowClicked.className = originalStyle;
}
}
頁
.normalRow{background-color: #FFFFFF;}
.alternateRow{background-color: #D3D3D3;}
.highlightRow{background-color: #F0E68C;}
代碼
Private Sub myGridView_RowCreated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles myGridView.RowCreated
Dim rowID As String = "row" + e.Row.RowIndex.ToString
If e.Row.RowState = DataControlRowState.Normal Then
e.Row.CssClass = "normalRow"
ElseIf e.Row.RowState = DataControlRowState.Alternate Then
e.Row.CssClass = "alternateRow"
End If
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("id", rowID)
e.Row.Attributes.Add("onclick",
"highlightRow('" & rowID & "', '" & e.Row.CssClass & "')")
End If
End Sub
的樣式210
適用於Chrome 12,Firefox 3.6和IE 8(正如我掌握的那些)。
歡迎。你會想要更具體的問題和標籤。我無法分辨您是在談論Android,WinForms,Qt還是小海豹。我甚至不確定你在使用什麼語言 - VB? – Cheezmeister
這是VS2010 NET4上的webform。正如twip指出的那樣。這必須在觸發onclick後儘快完成。 –