Access object through C# loop

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

Guest

I have an aspx page that contains 5 tables. Each table I have Named
tblSection1, tblSection2, tblSection3, tblSection4, tblSection5 respectively
and reside in a corresponding panel for collapse and placement purposes.

I have a loop in the code behind that will add rows and cells for each table
based on what is needed for that particular table. What I need to do is be
able to add a row to my table based on the pass of the loop I am in. Pass 1
add rows to tblSection1, Pass 2 add rows to tblSection2 and so on.. I am
having trouble calling the table control using the sectionCtr parameter as
seen below

My loop looks like this

//set up section count to also use as an input parm for the proc
int sectionCnt, sectionCtr;
sectionCnt = 1;

for(sectionCtr=1; sectionCtr <= sectionCnt; sectionCtr++)
{
//Run a bunch of code to populate DS and use results to build each table.
//....bla bla code

tblSection1.Rows.Add(tRow);
//I would like this to call the table based on the pass.
}

Any help is appreciated.
 
Define an array with the tables to use contained therein and use the
sectionCtr as the index into the array.

HTH,

Tim Wallace
 
This is what I did to solve it....

string str = "tblSection" + sectionCtr;
Table tblCtl = (System.Web.UI.WebControls.Table)FindControl(str);
tblCtl.Rows.Add(tRow);
 
Back
Top