473,472 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

adding image to table cell

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
Nov 18 '05 #1
2 12197
Manny Chohan wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
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

"Scott Mitchell [MVP]" wrote:
Manny Chohan wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

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

Nov 18 '05 #3

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

Similar topics

2
by: Chris Coho | last post by:
Is there any way to get the same affect as alt text for an image on a table cell? For instance I want if someone rolls the mouse over the cell for some instructions to pop up like they do for...
1
by: Kai Grossjohann | last post by:
I have a table which contains a top-aligned table cell: .... <tr style="height:40"> ... <td colspan="1" rowspan="2" align="left" valign="top" style="overflow:hidden;">...
23
by: MattB | last post by:
Hello please help, I have a table cell with a div in it. The div has a width of 300px. but when it is rendered it puts extra space into the table cell. Here's the style <style>...
7
by: John A. | last post by:
Hello all! I've got a big bunch of pages using tables for layout. Eventually I'll get them set up with more modernized code, but in the meantime I'd like to slip in a little quick holiday...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
5
by: Greg N. | last post by:
Hi folks, I have a table cell with a background image, something like <td background=landscape.jpg height=200></td> The sole purpose of this code is to display the image inside that table...
4
by: mscir | last post by:
When I try to use the DOM to add an image to a table cell, it works in IE but not in Netscape. If I look at the innerHTML of the table in Netscape I see %5C in place of "\" in the image file path,...
5
by: Doug Laidlaw | last post by:
HTML validators say that "background" is not a valid attribute for a <td> tag I want to set an image as the background for one cell only, and to have the cell content on top of it. If I can't...
3
by: Shawn | last post by:
Hi. I have an asp:table, like this: <asp:Table runat="server" id="Table1"> <asp:TableRow Runat="server"> <asp:TableCell id="tc1" Runat="server">&nbsp;</asp:TableCell> <asp:TableCell id="tc2"...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.