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

How to display images in datagrid column header?

P: n/a
Hi,

This must be simple, but I can't quite figure out how I can display images
in a header of a datagrid. For example, I need to display text followed by
the sort button (which is one of two images: ascending or descending)
followed by the help icon pointing to the help URL. Is this possible? Any
good methods of doing this? Thanks,

Alek
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Forgot to mention: I generate the image tag (with a hyperlink) dynamically
using a function in code behind. So I was looking to an option like this:

<ASP:TEMPLATECOLUMN
HeaderText='Info <%= GetHelpIconHtml("HelpTopicID") %>'>

The goal would be to produce HTML like this:

<TD...>Info <A Href=...><IMG Src=...></A></TD>

where <A Href.../A> is generated by the GetHelpIconHtml function in
code-behind.

Alek

"Alek Davis" <alek_xDOTx_davis_xATx_intel_xDOTx_com> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
Hi,

This must be simple, but I can't quite figure out how I can display images
in a header of a datagrid. For example, I need to display text followed by
the sort button (which is one of two images: ascending or descending)
followed by the help icon pointing to the help URL. Is this possible? Any
good methods of doing this? Thanks,

Alek

Nov 18 '05 #2

P: n/a
On Mon, 14 Jun 2004 15:23:10 -0700, Alek Davis
<alek_xDOTx_davis_xATx_intel_xDOTx_com> wrote:
Forgot to mention: I generate the image tag (with a hyperlink)
dynamically
using a function in code behind. So I was looking to an option like this:

<ASP:TEMPLATECOLUMN
HeaderText='Info <%= GetHelpIconHtml("HelpTopicID") %>'>

The goal would be to produce HTML like this:

<TD...>Info <A Href=...><IMG Src=...></A></TD>

where <A Href.../A> is generated by the GetHelpIconHtml function in
code-behind.

Alek


As you see, the DataColumn has a HeaderText property:

http://msdn.microsoft.com/library/en...rTextTopic.asp

it may be easier to do this in the code-behind than in the aspx binding
statement, even tho what you have looks OK as well. But you should be
able to use HTML like <img src=""...> in the HeaderText and it'll render
to an image when displayed. If you want to do it in the code-behind,
there is an ItemCreated event on the datagrid you can use in code-behind
and check e.Item.ItemType and if it's a header item type, you could set
the images then by adding controls to the e.Item.Cells. Or after binding,
you could go back and loop thru the cols and do it then (setting
col.HeaderText).

Here's a slightly different example, where the guy is setting his own
images in the header when sorting:

http://msdn.microsoft.com/library/en...rTextTopic.asp

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #3

P: n/a
OK, I figured it out. This can be done using <HEADERTEMPLATE> tags (right
before <ITEMTEMPLATE>). Inside of headertemplate, you can define any
controls, such as <ASP:LABEL>, etc., so I have three controls: one label for
header text label for help image URL, and one image for sorting. Wish
<HEADERTEMPLATE> were available via IntelliSense, it was just a lucky guess
(to use it) on my part.

"Alek Davis" <alek_xDOTx_davis_xATx_intel_xDOTx_com> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
Forgot to mention: I generate the image tag (with a hyperlink) dynamically
using a function in code behind. So I was looking to an option like this:

<ASP:TEMPLATECOLUMN
HeaderText='Info <%= GetHelpIconHtml("HelpTopicID") %>'>

The goal would be to produce HTML like this:

<TD...>Info <A Href=...><IMG Src=...></A></TD>

where <A Href.../A> is generated by the GetHelpIconHtml function in
code-behind.

Alek

"Alek Davis" <alek_xDOTx_davis_xATx_intel_xDOTx_com> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
Hi,

This must be simple, but I can't quite figure out how I can display images in a header of a datagrid. For example, I need to display text followed by the sort button (which is one of two images: ascending or descending)
followed by the help icon pointing to the help URL. Is this possible? Any good methods of doing this? Thanks,

Alek


Nov 18 '05 #4

P: n/a
Thanks Craig,

I posted a message before seeing your reply. The problem with HeaderText is
that it translates whatever is defined inside of the quotes as a literal, so
there is not way (at least, I do not see it) to get the value of header text
or a part of it by calling a code-behind function (notice that I did not do
it in code-behind, I just want to call a common function). In my example,
the header text will produce 'Info <%= GetHelpIconHtml("HelpTopicID") %>'
instead of returning the string generated by GetHelpIconHtml appended to
"Info ") as I would've expected. Anyway, I figured out how to do it, and it
is really simple (see my previous post). Thanks for response.

Alek

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op**************@craigd.javelintech.com...
On Mon, 14 Jun 2004 15:23:10 -0700, Alek Davis
<alek_xDOTx_davis_xATx_intel_xDOTx_com> wrote:
Forgot to mention: I generate the image tag (with a hyperlink)
dynamically
using a function in code behind. So I was looking to an option like this:
<ASP:TEMPLATECOLUMN
HeaderText='Info <%= GetHelpIconHtml("HelpTopicID") %>'>

The goal would be to produce HTML like this:

<TD...>Info <A Href=...><IMG Src=...></A></TD>

where <A Href.../A> is generated by the GetHelpIconHtml function in
code-behind.

Alek

As you see, the DataColumn has a HeaderText property:

http://msdn.microsoft.com/library/en...rTextTopic.asp
it may be easier to do this in the code-behind than in the aspx binding
statement, even tho what you have looks OK as well. But you should be
able to use HTML like <img src=""...> in the HeaderText and it'll render
to an image when displayed. If you want to do it in the code-behind,
there is an ItemCreated event on the datagrid you can use in code-behind
and check e.Item.ItemType and if it's a header item type, you could set
the images then by adding controls to the e.Item.Cells. Or after binding,
you could go back and loop thru the cols and do it then (setting
col.HeaderText).

Here's a slightly different example, where the guy is setting his own
images in the header when sorting:

http://msdn.microsoft.com/library/en...rTextTopic.asp
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.