How to add

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looping through a webcontrol Table and when I hit lets say 30th table
row, I want to append a string to whats already in the 30th row. Not sure
how to do that ... Here's what I have in place ...

int i = 1;
foreach(TableRow r in myTable.Rows)
{
if (i = 30)
{
//append "test:" to what already exists at that row
i=1; //reset i
}
i = i+1;
}

Appreciate your time. TIA.
 
exBK said:
I am looping through a webcontrol Table and when I hit lets say 30th table
row, I want to append a string to whats already in the 30th row. Not sure
how to do that ... Here's what I have in place ...

int i = 1;
foreach(TableRow r in myTable.Rows)
{
if (i = 30)
{
//append "test:" to what already exists at that row
i=1; //reset i
}
i = i+1;
}

Appreciate your time. TIA.

If you're going to use an index anyway, you might as well not use
foreach:

for (int i=0; i < myTable.Rows.Count; i++)
{
TableRow row = myTable.Rows;

if ((i % 30) == 0)
{
// whatever
}
// I assume you're doing something else here?
}

If you're not doing anything else in the loop, you can change it to:

for (int i=0; i < myTable.Rows.Count; i += 30)
{
// whatever
}
 
This is great help. However, how do I append a string to whats in the 30th
row?
if ((i % 30) == 0)
{
what do I need here to add a string to whats already in 30th row?
}

Thanks.

Jon Skeet said:
exBK said:
I am looping through a webcontrol Table and when I hit lets say 30th table
row, I want to append a string to whats already in the 30th row. Not sure
how to do that ... Here's what I have in place ...

int i = 1;
foreach(TableRow r in myTable.Rows)
{
if (i = 30)
{
//append "test:" to what already exists at that row
i=1; //reset i
}
i = i+1;
}

Appreciate your time. TIA.

If you're going to use an index anyway, you might as well not use
foreach:

for (int i=0; i < myTable.Rows.Count; i++)
{
TableRow row = myTable.Rows;

if ((i % 30) == 0)
{
// whatever
}
// I assume you're doing something else here?
}

If you're not doing anything else in the loop, you can change it to:

for (int i=0; i < myTable.Rows.Count; i += 30)
{
// whatever
}
 
exBK said:
This is great help. However, how do I append a string to whats in the 30th
row?
if ((i % 30) == 0)
{
what do I need here to add a string to whats already in 30th row?
}

Get the value from the column in the normal way, append some text to
it, and then set the value back into the column.
 
Back
Top