adding image to table cell

G

Guest

i am trying to add image to table cell. Here is my code..

System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl="http://localhost/Lhw/Images/i.p.new.gif";
for(int i=0; i < allRecords.Length; i++)
{
TableRow tRow = new TableRow();
Table2.Rows.Add(tRow);
TableCell tCell1= new TableCell();
tCell1.Controls.Add(img);
tRow.Cells.Add(tCell1);
}

The image doesnot appear when the page is run. Is there anything wrong.

Manny
 
S

Scott Mitchell [MVP]

Manny said:
i am trying to add image to table cell. Here is my code..

System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl="http://localhost/Lhw/Images/i.p.new.gif";
for(int i=0; i < allRecords.Length; i++)
{
TableRow tRow = new TableRow();
Table2.Rows.Add(tRow);
TableCell tCell1= new TableCell();
tCell1.Controls.Add(img);
tRow.Cells.Add(tCell1);
}

The code looks good. What is the HTML emitted?

Also, why are you manually creating a table like this? Might a
DataGrid, DataList, or Repeater be a better option?

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
G

Guest

The image should be in the first <td></td> tags, but it is completely empty.
<td></td><td></td><td>Caroline Pandolfo</td><td>FW: Employee Reports -
company Visits - IXOS LHW_EXLK 73
KB</td><td>2004-03-23T17:19:44.937Z</td><td>4647</td>

Manny
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top