You have several problems with your concept here:
i<e.Item.Cells.Count-1 would mean, if your loop did anything at all, that
you would never process the last cell. You should use i<e.Item.Cells.Count.
If you have 4 cells, you will iterate cells 0, 1, 2, 3. With the way you
have it, you would iterate cells 0, 1, 2.
Secondly, you don't ever reference i within your loop so why a for loop? It
is not clear how you are determining that i is not used. Your code should
loop through the columns, and therefore use i at least as the loop counter,
with the exception that I outlined in the first paragraph above: you will
never execute a count on the last column.
You call for Cells[3] in every iteration of your loop so you do exactly the
same thing each iteration. When your loop completes, Cells[3] is always
going to be FCA or Y since your last else will replace all the N values with
Y on the second iteration.
Next, why iterate the columns at all? Unless your entire data structure is
dynamic, then FCA should be in the same cell position, apparently in
Cells[3].
Perhaps you really mean to iterate through the rows using e.Items?
Also, you may want to replace your long series of if else statements with a
switch statement.
HTH
DalePres
MCAD, MCDBA, MCSE
"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
I am trying to iterate through a datagrid using the following code:
private void updateFCA(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for (int i = 0; i < e.Item.Cells.Count - 1; i ++)
{
if (e.Item.Cells[3].Text == "FCA")
{
e.Item.Cells[3].Text = "FCA";
}
else if (e.Item.Cells[3].Text == "")
{
e.Item.Cells[3].Text = "N";
}
else
{
e.Item.Cells[3].Text = "Y";
}
}
}
Thie iteration does not work as the int i value is not used. How do I
alter
the code to fix this problem?
Thanks,
Dave