473,544 Members | 1,969 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 5430
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
7226
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...
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
2474
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
2205
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...
1
1968
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...
3
1974
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
2928
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
3079
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
2195
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'...
0
1836
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...
0
7420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7362
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...
0
7602
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7764
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...
0
7704
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...
0
4911
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...
0
3404
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1837
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
0
657
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...

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.