Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a problem to show pictures dynamic in a table in the Page_Load() method, the pictures are not shown in the table cells and I don't know why.
Perhaps someone could help me?

C#
String[] pic_ending = new String[] { ".gif", ".png", ".jpg" };
int rows = quantity/3;

if ((quantity % 3) != 0) rows++;

int col = 3;
int number = 0; 
for (int r = 0; r < rows; r++)
{
	TableRow myRow = new TableRow();
	for (int c = 0; c < col; c++)
	{
		if (number == quantity) break;

		String picture = "";
		String[] allFiles = System.IO.Directory.GetFiles(name);

		foreach (String s in allFiles)
		{ 
			foreach (string p in pic_ending)
			{
				if (s.Contains(p)) picture = s;
				
				break;
			}
		}

		picture = picture.Replace("C:\\inetpub\\" ,"~/");
		picture = picture.Replace("\\", "/");

		TableCell myCell = new TableCell();
		myCell.Width = System.Web.UI.WebControls.Unit.Percentage(33);
		myCell.HorizontalAlign = HorizontalAlign.Center;
		myCell.Controls.Add(new LiteralControl("<asp:Image ID=\"Image" + number + "\" runat=\"server\" src=\"" + picture +"\"" + "/></br>" + distingtDir(name)));

		myRow.Cells.Add(myCell);

		number++;
	}
	UpperTable.Rows.Add(myRow);
}
Posted
Updated 18-Oct-11 4:23am
v2

1 solution

Where is UpperTable defined? Is it in the markup? If not, is it added to the controls collection?
 
Share this answer
 
Comments
kuti, ger 18-Oct-11 10:32am    
upperTable is defined as <asp:Table ID="UpperTable" runat="server" Width="90%" CssClass="table"> in the .aspx file
[no name] 18-Oct-11 10:46am    
First, I would use a Repeater or DataList and use databinding rather than manually creating a table.

Second, use an Image control rather than a literal.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900