Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - How to display images in datagrid column header?

 
Thread Tools Search this Thread
Old 06-14-2004, 11:14 PM   #1
Default How to display images in datagrid column header?


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




Alek Davis
  Reply With Quote
Old 06-14-2004, 11:23 PM   #2
Alek Davis
 
Posts: n/a
Default Re: How to display images in datagrid column header?
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:...
> 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
>
>





Alek Davis
  Reply With Quote
Old 06-14-2004, 11:57 PM   #3
Craig Deelsnyder
 
Posts: n/a
Default Re: How to display images in datagrid column header?
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


Craig Deelsnyder
  Reply With Quote
Old 06-15-2004, 12:08 AM   #4
Alek Davis
 
Posts: n/a
Default Re: How to display images in datagrid column header?
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:...
> 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:...
> > 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
> >
> >

>
>





Alek Davis
  Reply With Quote
Old 06-15-2004, 12:17 AM   #5
Alek Davis
 
Posts: n/a
Default Re: How to display images in datagrid column header?
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...
> 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





Alek Davis
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Display And Edit Multiline In Datagrid Controls With Databinding.. har29oct General Help Related Topics 0 03-28-2009 02:41 PM
Loading 24,000 rows into C# .net Datagrid Kagu Software 0 03-10-2009 06:51 PM
Blur Images Display DKS General Help Related Topics 0 06-03-2008 04:14 PM
HDDVD/Bluray: stillborn or coma Rexunrex@yahoo.com DVD Video 586 01-31-2007 07:05 PM
How to keep images on DVD from being copied WVAngel Software 0 11-18-2006 03:39 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46