473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Usercontrol not rendered in table

I am programmatically populating a asp.net table control with my usercontrol
(PictureBox.ascx) which is basically an assortment of an imagebutton, Label
and a Linkbutton. Now while debugging the application i can see that the
control is being initialized properly (by setting the imgurl and text values
from the db), but for some reason the usercontrol does not show up in the
table.

Here is the code for the Page: (test.aspx)
//I am calling the ArrangePictures() function on the click event of a button
which basically starts to load a list of usercontrols

/////////////////////////////////////////////////////////////////////

private void ArrangePictures()

{

ArrayList Pics = LoadPictures();

TableRow r = new TableRow();

TableCell c;

foreach (object P in Pics)

{

c = new TableCell();

//this is where i am adding the control

//it does not throw any errors but instead

//spits out an empty cell

c.Controls.Add(((PictureBox)P));

r.Cells.Add(c);

if (r.Cells.Count == 3)

{

tblPictures.Rows.Add(r);

r = new TableRow();

}//if - Pics

}//foreach

if (r.Cells.Count == 2)

{

c = new TableCell();

c.ColumnSpan = 2;

r.Cells.Add(c);

tblPictures.Rows.Add(r);

}

else

{

c = new TableCell();

c.ColumnSpan = 2;

r.Cells.Add(c);

tblPictures.Rows.Add(r);

}

}//Arrange pictures

////////////////////////////////////////////////////////////////////////////////////

private ArrayList LoadPictures()

{

OleDbDataReader rdrImages = getPictureData();

ArrayList Pictures = new ArrayList();

PictureBox Picture;

if (rdrImages.Read())

{//Skip first file - will be used in header

while (rdrImages.Read())

{

Picture = new PictureBox();

Picture.Picture.ImageUrl = Convert.ToString(rdrImages.GetValue(2));

Picture.Picture.AlternateText = Convert.ToString(rdrImages.GetValue(1));

Picture.TextCaption.Text = Convert.ToString(rdrImages.GetValue(1));

Pictures.Add(Picture);

}//while

}//if

if ((Pictures.Count < 9) && (Session["UserId"] == Session["ID"]))

{//add upload picture control if user is logged into their account

Picture = new PictureBox();

Picture.TextCaption.Text = "Add a new picture.";

Picture.Picture.ImageUrl = Request.ApplicationPath + "/images/add.jpg";

Picture.Picture.AlternateText = "Add a new picture.";

Pictures.Add(Picture);

}//if

return Pictures;

}//LoadPictures


Code for the user Control (PictureBox.ascx):
private ImageButton _Picture;

private Label _Caption;

public ImageButton Picture

{

get

{

_Picture.Height = Unit.Pixel(80);

_Picture.Width = Unit.Pixel(80);

return _Picture;

}

set

{

_Picture = value;

}

}

public Label TextCaption

{

get

{

return _Caption;

}

set

{

_Caption = value;

}

}

public PictureBox()

{

this.TextCaption = new Label();

this.Picture = new ImageButton();

}

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

lblCaption = this.TextCaption;

ibtnPicture = this.Picture;

}


Also, how would i be able to add onclick events for these dynamically loaded
controls. (ex. for ImageButton)
Jul 21 '05 #1
0 912

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anon | last post by:
I am programmatically populating a asp.net table control with my usercontrol (PictureBox.ascx) which is basically an assortment of an imagebutton, Label and a Linkbutton. Now while debugging the...
0
by: Anon | last post by:
I am programmatically populating an asp.net table control with my usercontrol (PictureBox.ascx) which is basically an assortment of an imagebutton, Label and a Linkbutton. Now while debugging the...
0
by: Anon | last post by:
I am programmatically populating a asp.net table control with my usercontrol (PictureBox.ascx) which is basically an assortment of an imagebutton, Label and a Linkbutton. Now while debugging the...
1
by: SlimFlem | last post by:
I hope this makes sense. Here is what I am attempting. I have an inital generic aspx page that has one custom tag: <web:site id=webSite runat=server/> When this control evaluates, it will...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.