473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

<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 programmatically 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.aspx?SomeVar1=23&AnotherVar=9&Des=Thi s+is+the+text+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 5412
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(object sender, EventArgs e)
{
Table tbl=new Table();
TableCell cell= new TableCell();
TableRow row=new TableRow();
HyperLink hlnk=new HyperLink();
hlnk.NavigateUrl="MyPage.aspx?SomeVar1=23&AnotherV ar=9&Des=This+is+the+text+description";
hlnk.ImageUrl="http://www.gc.ca/images/canada.gif";
cell.Controls.Add(hlnk);
hlnk=new HyperLink();
hlnk.NavigateUrl =
"MyPage.aspx?SomeVar1=23&AnotherVar=9&Des=This+is+ the+text+description";
hlnk.Text="<br>Here is another description - under the image";
cell.Controls.Add(hlnk);
row.Cells.Add(cell);
tbl.Rows.Add(row);
Page.Controls.Add(tbl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled 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****************@TK2MSFTNGP09.phx.gbl...
Okay - I'm spinning my wheels on this one... can someone help me figure
out
how to programmatically 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.aspx?SomeVar1=23&AnotherVar=9&Des=Thi s+is+the+text+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.add(img);
hyp.controls.add(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****************@TK2MSFTNGP09.phx.gbl...
Okay - I'm spinning my wheels on this one... can someone help me figure out
how to programmatically 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.aspx?SomeVar1=23&AnotherVar=9&Des=Thi s+is+the+text+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.org> wrote in message
news:uN**************@TK2MSFTNGP10.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.add(img);
hyp.controls.add(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****************@TK2MSFTNGP09.phx.gbl...
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically 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.aspx?SomeVar1=23&AnotherVar=9&Des=Thi s+is+the+text+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
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...
0
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...
32
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:...
1
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...
1
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...
3
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...
5
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...
6
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...
2
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 =...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.