I have been attempting to add a background color to a grid view row when clicked on that specific row.
<script type="text/javascript">
function ChangeRowColor(objref) {
objref.style.backgroundcolor = "red";
}
</script>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
string rowID = String.Empty;
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "ChangeRowColor(this)");
}
}
However, despite my efforts, nothing happens when I click on the row. Can someone please assist me in resolving this issue?