Building a table from within a loop

G

Grant

Hi,

Ive got this loop within a loop and Im trying to build a table. Problem is
when I exit the 2nd foreach loop (having created a new row) I cant add the
new row because it isnt in scope anymore. Basically I have this custom
arraylist containing a name property which has multiple attributes. I loop
through the values and foreach value I do a 2nd loop to get all the values
attributes. So I guess my question is how would I build a table with 2
columns? 1st column containing the value and the 2nd column containing the
values? so it should look something like:

property1 | property attribute
| property attribute
| property attribute
Property2 | property2 attribute
Property2 | property2 attribute
etc...

Heres my code:
-----------------------------------------------------
foreach ( CustomArrayList _object in _GlobalPropertyValues )
{ //Create a table cell for user names
usernameCell = new TableCell();
usernameCell.BorderStyle = BorderStyle.Solid;
usernameCell.Text = _object.propertyName;

foreach ( string _propertyName in _object )
{ //Create another table cell for user AD paths
userContainerCell = new TableCell();
userContainerCell.BorderStyle = BorderStyle.Solid;
userContainerCell.Text = _propertyName;

//Construct the table rows
newRow = new TableRow();
newRow.Cells.Add( userContainerCell );
tblResults.Rows.Add( newRow );
}
//Add the cells to the table row
newRow = new TableRow();
newRow.Cells.Add( usernameCell );
//newRow.Cells.Add( userContainerCell );
tblResults.Rows.Add( newRow );
}
-----------------------------------------------------

The code above produces a single column table.


Thanks for any help on this!

Cheers,
Grant
 
S

Sergio Florez M.

When I dinamically create tables I don't add the TableRows to the table's
Rows collection, I add them directly to its Controls collection. Same thing
with TableCells to TableRows. Never had a problem using this approach so
maybe you should try it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,889
Messages
2,569,968
Members
46,300
Latest member
XWPMalissa

Latest Threads

Top