G
gnewsgroup
I have a GridView which is bound to my database.
The leftmost column of the GridView has a value of either 0 or 1,
and I need to highlight the cell of column 3 if the leftmost column
has a value of 0. After highlighting, I want the leftmost column to
disappear.
So, in the OnDataBound event handler, I call a method HighlightCells()
which looks like this (code from my memory):
foreach (GridViewRow gvr in myGridView.Rows)
{
if (myGridView.Columns[0].Text.Equals("0"))
{
Label lbl = new Label();
lbl.Text = gvr.Cells[2].Text;
lbl.BackColor = Color.Yellow;
gvr.Cells[2].Text = String.Empty;
gvr.Cells[2].Controls.Add(lbl);
}
// Now let the leftmost column disappear!
myGridView.Columns[0].Visible = false;
}
The logic looks OK, right? It indeed works a little. myGridView
allows paging. Cells are not highlighted if I click page index to go
to another page. I did call HighlightCells() in the
OnPageIndexChanging event handler.
What is wrong? Or is there a better strategy to achieve my goal?
Thanks.
The leftmost column of the GridView has a value of either 0 or 1,
and I need to highlight the cell of column 3 if the leftmost column
has a value of 0. After highlighting, I want the leftmost column to
disappear.
So, in the OnDataBound event handler, I call a method HighlightCells()
which looks like this (code from my memory):
foreach (GridViewRow gvr in myGridView.Rows)
{
if (myGridView.Columns[0].Text.Equals("0"))
{
Label lbl = new Label();
lbl.Text = gvr.Cells[2].Text;
lbl.BackColor = Color.Yellow;
gvr.Cells[2].Text = String.Empty;
gvr.Cells[2].Controls.Add(lbl);
}
// Now let the leftmost column disappear!
myGridView.Columns[0].Visible = false;
}
The logic looks OK, right? It indeed works a little. myGridView
allows paging. Cells are not highlighted if I click page index to go
to another page. I did call HighlightCells() in the
OnPageIndexChanging event handler.
What is wrong? Or is there a better strategy to achieve my goal?
Thanks.