Datagrid
DataGrid Click a row to change the background color of this row
1 Set the Alternatingitemstyle.backcolor property of the DataGrid control to "beige".
2 events fired when the DataGrid control creates an item (datagrid1_itemcreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) ), add the following code:
private void Datagrid1_itemcreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (E.item.itemindex >-1)
{
e.item.attributes["name"] = "selecttr";
e.item.attributes["onclick"] = "Selectnode (this)";
}
}
3 Add JavaScript code to the HTML code page as follows:
function Selectnode (objthis)
{
var objtrs = document.getElementsByTagName ("TR");
var j = 0;
for (var i = 0; i < objtrs.length-1 i = i + 2)
{
j = i + 1;
if (Objtrs[i].name = = "Selecttr")
Objtrs[i].style.backgroundcolor = "Beige";
if (Objtrs[j].name = = "Selecttr")
Objtrs[j].style.backgroundcolor = "#ffffff";
}
ObjThis.style.backgroundColor = "#c6ff00";
}
You might as well try! ^_^