Following javascript will be used to change the color of the row.
<script type="text/javascript">
var previousRow;
function ChangeRowColor(row)
{
if (previousRow == row)
return; else if (previousRow != null)
document.getElementById(previousRow).style.backgroundColor = "#ffffff";
document.getElementById(row).style.backgroundColor = "#ffffda";
previousRow = row;
}
</script>
Following code will be required on GridView1_RowDataBound event
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" & e.Row.ClientID & "')")
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'FillDataTable is a function that will return a DataTable
'with some values and is available in the code for download.
Me.GridView1.DataSource = Me.FillDataTable()
Me.GridView1.DataBind()
End If
End Sub
Before clicking the row
After clicking the row