forum

Home / DeveloperSection / Forums / GridView RowDataBound For Loop Not Working

GridView RowDataBound For Loop Not Working

Barbara Jones 2179 21-Nov-2014

I have a column that looks like this

1 1 5 1 1 1 5 1 1 1 2 1
2 3 1 1 1 1 3

What I want to do highlight everything between 5 and 5 and everything between 2 and 2 etc... However the script below stops after the first section. I want it to loop through all the rows in the grid view.

[code]
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < 1; i++)
        {
            bool begin = false;
            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.Cells[i + 2].Text != "1")
                {
                    row.Cells[i + 2].BackColor = System.Drawing.Color.Blue;
                    if (!begin) begin = true;
                    else
                        break;
                }
                if (begin) row.Cells[i + 2].BackColor = System.Drawing.Color.Blue;
            }
        }
    }


Updated on 21-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By