Concatenating Object instance name in loop???

I

Isz

I can do this easily enough in actionscript, but I would like to do it also
in C#. I have 10 Image controls on the .aspx page. I want to create a
loop that makes the first 'n' number of Images' control prroperty visible =
true.

My Image controls are named: Image1, Image2, Image3... etc.

In actionscript I would do something like this...

this["image" + n].visible = true;

How can you concatenate an object instance name?

Isz
 
W

William Stacey [MVP]

PictureBox[] pba = new PictureBox[2];

pba[0] = new PictureBox();

pba[1] = new PictureBox();

pba[0].Visible = false;

....
 
I

Isz

PictureBox[] pba = new PictureBox[2];

pba[0] = new PictureBox();

pba[1] = new PictureBox();

pba[0].Visible = false;

...

Most Excellent! This is just what i needed to get what i want
accomplished... here is the code I actually ended up using (I was
developing for a webform)...

while(reader2.Read())
{
ObjectPics thisPics = new ObjectPics();
thisPics.pictureID = reader2.GetInt32(0);
thisPics.pictureName = reader2.GetString(1);
thisPics.pictureLocation = reader2.GetString(2);
thisPics.itemID = reader2.GetInt32(3);
picSetArray.Add(thisPics);

imageArray[count] = new System.Web.UI.WebControls.Image();
imageArray[count].Visible = true;
imageArray[count].ImageUrl = thisPics.pictureLocation +
thisPics.pictureName;
Page.Controls.Add(imageArray[count]);
count += 1;


}
 
W

William Stacey [MVP]

Cool. glad that go you going. Cheers!

--
William Stacey, MVP

Isz said:
PictureBox[] pba = new PictureBox[2];

pba[0] = new PictureBox();

pba[1] = new PictureBox();

pba[0].Visible = false;

...

Most Excellent! This is just what i needed to get what i want
accomplished... here is the code I actually ended up using (I was
developing for a webform)...

while(reader2.Read())
{
ObjectPics thisPics = new ObjectPics();
thisPics.pictureID = reader2.GetInt32(0);
thisPics.pictureName = reader2.GetString(1);
thisPics.pictureLocation = reader2.GetString(2);
thisPics.itemID = reader2.GetInt32(3);
picSetArray.Add(thisPics);

imageArray[count] = new System.Web.UI.WebControls.Image();
imageArray[count].Visible = true;
imageArray[count].ImageUrl = thisPics.pictureLocation +
thisPics.pictureName;
Page.Controls.Add(imageArray[count]);
count += 1;


}
 

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

Top