473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<a... <img..>> in a <td> from code-behind... this can't be that hard

Okay - I'm spinning my wheels on this one... can someone help me figure out
how to programmaticall y populate a table cell as follows (from C#
code-behind)? I've tried using a Literal control in the TableCell, a
HyperLink control, and an Image, but I'm not getting the results I want.

Here's the source of what I'm after (retrieved by viewing the source of a
page I'm trying to emulate):

<td><a
href="MyPage.as px?SomeVar1=23& AnotherVar=9&De s=This+is+the+t ext+description .
+"><img border=0 alt="Pick me" src="../images/myImage.gif"/><br>Here is
another description - under the image</a><br><br></td>

Basically the ultimate result I'm after is a two-column list of icons with a
bit of text underneath. Clicking the icon or associated text results in
going to the same destination. The table provides the layout of the
icons-with-text. Most variables (image paths, etc) get populated from a
database.

Any help would be GREATLY appreciated.
Nov 18 '05 #1
3 5453
Hi Henry,

You just need to understand how to build tables, rows, cells and other items
and add them to each other. It is like those Russian dolls where small parts
are contained inside bigger and bigger ones.

Here's some code using the brand new Visual Studio 2005 Express beta:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">

void Page_Load(objec t sender, EventArgs e)
{
Table tbl=new Table();
TableCell cell= new TableCell();
TableRow row=new TableRow();
HyperLink hlnk=new HyperLink();
hlnk.NavigateUr l="MyPage.aspx? SomeVar1=23&Ano therVar=9&Des=T his+is+the+text +description";
hlnk.ImageUrl=" http://www.gc.ca/images/canada.gif";
cell.Controls.A dd(hlnk);
hlnk=new HyperLink();
hlnk.NavigateUr l =
"MyPage.aspx?So meVar1=23&Anoth erVar=9&Des=Thi s+is+the+text+d escription";
hlnk.Text="<br> Here is another description - under the image";
cell.Controls.A dd(hlnk);
row.Cells.Add(c ell);
tbl.Rows.Add(ro w);
Page.Controls.A dd(tbl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

Ken
Microsoft MVP [ASP.NET]
"Henry Johnson" <ok**@dokey.com > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Okay - I'm spinning my wheels on this one... can someone help me figure
out
how to programmaticall y populate a table cell as follows (from C#
code-behind)? I've tried using a Literal control in the TableCell, a
HyperLink control, and an Image, but I'm not getting the results I want.

Here's the source of what I'm after (retrieved by viewing the source of a
page I'm trying to emulate):

<td><a
href="MyPage.as px?SomeVar1=23& AnotherVar=9&De s=This+is+the+t ext+description .
+"><img border=0 alt="Pick me" src="../images/myImage.gif"/><br>Here is
another description - under the image</a><br><br></td>

Basically the ultimate result I'm after is a two-column list of icons with
a
bit of text underneath. Clicking the icon or associated text results in
going to the same destination. The table provides the layout of the
icons-with-text. Most variables (image paths, etc) get populated from a
database.

Any help would be GREATLY appreciated.


Nov 18 '05 #2
I'm not a C#'er, so the syntax may be off, but this should work for you. Just set the attributes you need on each control.

TableCell td = new tablecell();
Hyperlink hyp = new hyperlink();
Image img = new Image();

hyp.controls.ad d(img);
hyp.controls.ad d(new LiteralControl( "<br>Here is another description..." ));
td.controls.add (hyp);
td.controls.add (new LiteralControl( "<br><br>") ;

--Michael

"Henry Johnson" <ok**@dokey.com > wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Okay - I'm spinning my wheels on this one... can someone help me figure out
how to programmaticall y populate a table cell as follows (from C#
code-behind)? I've tried using a Literal control in the TableCell, a
HyperLink control, and an Image, but I'm not getting the results I want.

Here's the source of what I'm after (retrieved by viewing the source of a
page I'm trying to emulate):

<td><a
href="MyPage.as px?SomeVar1=23& AnotherVar=9&De s=This+is+the+t ext+description .
+"><img border=0 alt="Pick me" src="../images/myImage.gif"/><br>Here is
another description - under the image</a><br><br></td>

Basically the ultimate result I'm after is a two-column list of icons with a
bit of text underneath. Clicking the icon or associated text results in
going to the same destination. The table provides the layout of the
icons-with-text. Most variables (image paths, etc) get populated from a
database.

Any help would be GREATLY appreciated.

Nov 18 '05 #3
Thank you Michael (and Ken Cox)... Two solutions that provide the desired
effect; primary difference being that Michael's nests the <img> within the
<a> tag in the rendered HTML (as I prefer in this instance), whereas Ken's
provides two <a> tags... each solution with its own merits.

Cheers!
"Raterus" <ra*****@spam.o rg> wrote in message
news:uN******** ******@TK2MSFTN GP10.phx.gbl...
I'm not a C#'er, so the syntax may be off, but this should work for you.
Just set the attributes you need on each control.

TableCell td = new tablecell();
Hyperlink hyp = new hyperlink();
Image img = new Image();

hyp.controls.ad d(img);
hyp.controls.ad d(new LiteralControl( "<br>Here is another description..." ));
td.controls.add (hyp);
td.controls.add (new LiteralControl( "<br><br>") ;

--Michael

"Henry Johnson" <ok**@dokey.com > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmaticall y populate a table cell as follows (from C#
code-behind)? I've tried using a Literal control in the TableCell, a
HyperLink control, and an Image, but I'm not getting the results I want.

Here's the source of what I'm after (retrieved by viewing the source of a
page I'm trying to emulate):

<td><a
href="MyPage.as px?SomeVar1=23& AnotherVar=9&De s=This+is+the+t ext+description . +"><img border=0 alt="Pick me" src="../images/myImage.gif"/><br>Here is
another description - under the image</a><br><br></td>

Basically the ultimate result I'm after is a two-column list of icons with a bit of text underneath. Clicking the icon or associated text results in
going to the same destination. The table provides the layout of the
icons-with-text. Most variables (image paths, etc) get populated from a
database.

Any help would be GREATLY appreciated.

Nov 18 '05 #4

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

Similar topics

4
7278
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but this only gives me table rows with no table data cells. So I would like to know if it's possible to create several <TH> within the tHead row using this method?
0
689
by: Matt Adams | last post by:
I want to move the following <PRE> defintion to a css file: <TABLE><TR><TD><PRE>sample text</PRE></TD> <TD> not predefined font</TD></TR></TABLE> should be <TABLE><TR><TD class=aaa>sample text</TD> <TD> not predefined font</TD></TR></TABLE>
32
2535
by: Werner Partner | last post by:
Hier is the problem: http://asterix/sonoptikon.de/artemis/index.php The <h1> and <h2> make their ellbows so broad that in the picture arise borders on top and bottom. The general question is: How can I force left frame and banner to be exactly as broad resp. as high as the picture?
1
2246
by: prefersgolfing | last post by:
I'm not using Master Pages, yet I'd like to display the contents of an HTML page within a <table><tr><td> on a .aspx. I have a lengthy guide already paginated in html. I'd like to embed the pages "as is" in the new 2.0 app without using Master Pages or creating new ..aspx's. I'm looking for the quickest way to the finish line. Any suggestions would be welcomed. Thanks.
1
1979
by: Santos L Halper | last post by:
this will be hard to explain. picture a <tablewith 3 columns. if you type text into the center column and hit enter a bunch of times, all 3 columns expand vertically to fit the content you put in the middle column. I want to duplicate this with <divtags. if I have 3 <div>'s floating next to each other so that they line up, and I type and hit enter in the middle div, it grows vertically while the other 2 stay put. is there any way to...
3
2000
by: Manish Sawjiani | last post by:
Dear experts i have just migrated from asp to asp.net and i am missing the loop for creating tables. while in asp one could just start a loop anywhere withing <% %is this out of style in the .Net Scenario? Thanks Manish --
5
2938
by: mahesr | last post by:
I want to match some particular text between <tr>and </tr> or <td>and </td>.... in PHP. like below............ <table><tr> CATEGORY: <td><font face="Verdana" size="1" color="#A000A0"> Wedding Accessories
6
3094
by: Summercool | last post by:
I just found that for a table, the margin for <trand <tdare not honored, but the padding is... is this a widely known fact? why make this an exception for margin, i wonder. margin not honored: http://www.0011.com/test_table/index-margin.html padding honored: http://www.0011.com/test_table
2
2206
by: jessy | last post by:
I have a table at which i need to add fields in it whenever the user clicks on the Add button , here's my trial but seems sth is wrong : function AddTool() { formdiv = document.getElementById('1'); formdiv.innerHTML = formdiv.innerHTML +'<td align='center'><a href='#'><img border='0' src='../images/delete.gif'></td> '; } thats the Js function and thats the table which is generated through looping:
0
1851
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've created my table and alli is fine. I name my <tdtags to make them easier to identify when my table gets large. Anyway, I am naming as such: <td id="cellName" > Now, sometimes when make a change to a control my whole table gets resized and screwed up from some reason. I may have a column with a width of 75px, but it will appear so narrow it is hardly visible. Anyway, in these cases I undo what made this happen and the table fixes...
0
9492
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
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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
6744
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
5397
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
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
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
3
2894
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.