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 KharadPosted Nov 14, 2011, 4:34 AM
{
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 KharadPosted Nov 14, 2011, 10:15 AM
nishant ranjanPosted Nov 14, 2011, 5:23 AM
Datta KharadPosted Nov 14, 2011, 4:32 AM
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';
}
}
}
}
}
}