i have a grid view whose each row color is white. i have a button outside somewhere in page(button is not in grid view).
say the button text is next.
what i want is, when i click button for first time, the first row color should change to green. when i click button second time then first row color should change to yellow and second row color to green. on third click 1st and 2nd row color to yellow and third row to green and so on.
Loading

Datta KharadRank #2,135 · 668 reputationPosted Nov 13, 2011, 11:34 PM EST
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
foreach (GridViewRow row in GridView1.Rows)
{
row.BackColor = row.RowIndex.Equals(rowIndex) ?
System.Drawing.Color.Red :
System.Drawing.Color.White;
}
}
Datta KharadRank #2,135 · 668 reputationPosted Nov 13, 2011, 11:32 PM EST
You can write javascript code..
function ChangeColor() {
//get reference of GridView control
var grid = document.getElementById("grd2");
//variable to contain the cell of the grid
var cell;
if (grid.rows.length > 0) {
//loop starts from 1. rows[0] points to the header.
for (i = 1; i < grid.rows.length; i++) {
//get the reference of first column
cell = grid.rows[i].cells[0];
//loop according to the number of childNodes in the cell
for (j = 0; j < cell.childNodes.length; j++) {
//if childNode type is CheckBox
if (cell.childNodes[j].type == "checkbox") {
//assign the status of the Select All checkbox to the cell checkbox within the grid
if (cell.childNodes[j].checked == true) {
alert();
grid.rows[i].style.backgroundColor = 'Red';
}
}
}
}
}
}
nishant ranjanRank #4,961 · 317 reputationPosted Nov 14, 2011, 12:23 AM EST
Datta KharadRank #2,135 · 668 reputationPosted Nov 14, 2011, 5:15 AM EST