Adding image from code behind

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

Hi.
I have an asp:table, like this:

<asp:Table runat="server" id="Table1">
<asp:TableRow Runat="server">
<asp:TableCell id="tc1" Runat="server">&nbsp;</asp:TableCell>
<asp:TableCell id="tc2" Runat="server">&nbsp;</asp:TableCell>
</asp:TableRow>
</asp:Table>

How can I add a background image to the TableCells from code behind?

Thanks,
Shawn
 
Shawn,

Make a css style with atribute background-image set to your image. Set
CssClass property for TableCell into the style name.

Eliyahu
 
Thanks for quick answer!

The thing is that the background image is an embedded resource so I don't
think I can't use that method.
Do you know of another way?

Thanks,
Shawn
 
One second. Whatever place your image is in on the server, the client can
get it only by url. So you have to provide the client with the url to the
image. It doesn't mean you have to export the image in a separate file. You
can make a page that will accept an image id as a parameter, get the image
from the resource and then stream it down to the client, in the way how
database-stored images get sent to clients. But as far as table cell setting
is concerned, you should do it in the way I suggested. The css rule can look
like

background-image : "getImage.aspx?id=1";

Eliyahu
 
Back
Top