1.Through javascript:
function ChangeRowColor(rowID)
{
var color = document.getElementById(rowID).style.backgroundColor;
if(color != '#6aafaf')
oldColor = color;
if(color == '#6aafaf')
document.getElementById(rowID).style.backgroundColor = oldColor;
else
document.getElementById(rowID).style.backgroundColor = '#6aafaf';
}
Call this function in GridView Row create event
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
string rowID = String.Empty;
if (e.Row.RowType == DataControlRowType.DataRow)
{
rowID = "row"+e.Row.RowIndex;
e.Row.Attributes.Add("id","row"+e.Row.RowIndex);
e.Row.Attributes.Add("onclick","ChangeRowColor(" +"'" + rowID + "'" + ")");
}
}
2.Through coding
make a function in code behind
protected void ChangeRowColor(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowIndex == GridView1.SelectedIndex)
{
row.BackColor = ColorTranslator.FromHtml("#6aafaf");
}
else
{
row.BackColor = ColorTranslator.FromHtml("#93acae");
}
}
}
call this function on Gridview event
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" onselectedindexchanged="ChangeRowColor" xmlns:asp="#unknown"></asp:gridview>
Hope this help.
Thanks