473,800 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
+ 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.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();
img.ImageUrl="h ttp://localhost/Lhw/Images/i.p.new.gif";
for(int i=0; i < allRecords.Leng th; 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 12240
Manny Chohan wrote:
i am trying to add image to table cell. Here is my code..

System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();
img.ImageUrl="h ttp://localhost/Lhw/Images/i.p.new.gif";
for(int i=0; i < allRecords.Leng th; 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******@4guysf romrolla.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.937 Z</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.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();
img.ImageUrl="h ttp://localhost/Lhw/Images/i.p.new.gif";
for(int i=0; i < allRecords.Leng th; 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******@4guysf romrolla.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
17092
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 images when you have alt text. I know how to do mouse over effects and onmousein and onmouseout. I just dont know how to get the same text box style as image alt text. Thanks in advance!!
1
8457
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;"> ...contents.explained.later... </td> ...
23
18646
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> #treecontainer {
7
10447
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 decoration. I'd like to insert a table cell with a fixed width (as much as such things can be fixed) and a repeating garland background so as to show up along the left side of the table, repeating down its length. Our site has a couple thousand...
7
18926
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 = "absolute"; t.style.left = "100px"; t.style.top = "100px"; t.style.width = "200px";
5
3901
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 cell. It displays just as much of the image as the current cell width allows. The actual cell width is determined by other cells in the same table column and by the current browser window width.
4
1765
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, nothing I do corrects it. e.g. <td><img src="C:%5CArchive%5Cgraphic%5C2pitvipers.jpg"></td> Does anyone have any suggestions? TIA, Mike
5
3449
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 use <td background="img src=.."></td>, what is the correct method? Some modern templates do it all with CSS, but that is getting a bit too deep for my inexperience.
3
8802
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" Runat="server">&nbsp;</asp:TableCell> </asp:TableRow> </asp:Table>
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.