adding HTML formatting to a datagrid

B

Ben

Hello,

I have a datagrid in an .aspx page that I'd like to add some HTML
formatting to:

<asp:BoundColumn DataField="Pict1" HeaderText="Picture" />
<asp:BoundColumn DataField="PropertySite" HeaderText="Official
Site" />

The value returned from the datafield Pict1 is simply
"/images/pict1.jpg"
and the value returned by the datafield PropertySite is simply
"http:/website.com"

I'd like to add HTML formatting to every value in Pict1 that so that
"images/pict1.jpg" becomes <img border="0" src="images/pict1.jpg"
width="999" height="999"> and therefore shows a picture in the
datagrid.

I'd like to add similar formatting so that the value in PropertySite
is an actual hyperlink.

Can someone tell me how this might be possible? If I've posted to the
wrong group I'd appreciate being directed to the correct one.
 
E

Eliyahu Goldin

The direction: instead of BoundColumn use TemplateColumn. Put the <img> into
the item template and databind src property to Pict1.

Eliyahu
 
B

Ben

Eliyahu Goldin said:
The direction: instead of BoundColumn use TemplateColumn. Put the <img> into
the item template and databind src property to Pict1.

Eliyahu
 
B

Ben

I was able to use a "hyperlinkcolumn" to get the what I wanted as seen in the code below:

<asp:HyperLinkColumn HeaderText="Property Site" DataTextField="PropertySite"></asp:HyperLinkColumn>

But I could not get the image to work using Eliyahu instructions. Can someone send me the code syntax?
Thanks, -Ben
 
E

Eliyahu Goldin

Ben,

Add a template column <asp:TemplateColumn ...> and in it use
<ItemTemplate>
<img border="0" src=<%# DataBinder.Eval (Container.DataItem, "Pict1") %>
width="999" height="999">
</ItemTemplate>

Eliyahu

Ben said:
I was able to use a "hyperlinkcolumn" to get the what I wanted as seen in the code below:

<asp:HyperLinkColumn HeaderText="Property Site"
DataTextField="PropertySite"> said:
But I could not get the image to work using Eliyahu instructions. Can
someone send me the code syntax?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top