Re: Creating variables in a loop!
- From: Todd Jaspers <ToddJaspers@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 3 Apr 2007 12:54:03 -0700
Mark, thanks for the response, I appreciate it.
It appears to work, the only thing I'm a little bit confused on is how I
retrieve the information (the boolean checked or not checked) back from the
variable if the variable is in fact the same for each one?
Any hints on how I might be able to retrieve the boolean state of each of
them after the grid / table has already been built?
Thanks!!!
Todd
"Mark Fitzpatrick" wrote:
No. It also wouldn't do much good as a variable is only alive for the scope.
of the loop and doesn't exist outside it. Keep in mind, you are creating an
object here, specifically object inherited from a webcontrol object. That
means you have a property available to you that you can set the ID of the
resultant control. The tmCell.ID property would allow you to set the name of
the control. You may also want to set the AccessKey property as well. Try
playing with this concept a bit as even if you could alter the name of the
variable in the loop, it doesn't do you any good as that reference is
useless the second you iterate through the loop again, or after the loop
completes.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Todd Jaspers" <ToddJaspers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A6D24909-8BE9-4AF3-916E-F12B938AD29A@xxxxxxxxxxxxxxxx
Hey guys,
Is there ANY way to accomplish this: (see below)? Basically, I want
to
have a loop (a < 3 is just for testing purposes, it will be an
underermined
amount). In this loop, I want to be able to create a new cell each time.
In
this cell, I want the variable name to change. Is this at ALL possible?
I've
never been able to figure this out in some of the other languages.
Any help would GREATLY be appreciated.
TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}
would it be something like this???
TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!
- Follow-Ups:
- Re: Creating variables in a loop!
- From: Hans Kesting
- Re: Creating variables in a loop!
- References:
- Re: Creating variables in a loop!
- From: Mark Fitzpatrick
- Re: Creating variables in a loop!
- Prev by Date: Re: What to consider when using SqlDatASource programmatically?
- Next by Date: Re: Handling session timeout exception
- Previous by thread: Re: Creating variables in a loop!
- Next by thread: Re: Creating variables in a loop!
- Index(es):
Relevant Pages
|