By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.