![]() |
|
|
|||||||
![]() |
ASP Net - How to display images in datagrid column header? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: 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:... > 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 |
|
|
|
#3 |
|
Posts: 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 Craig Deelsnyder |
|
|
|
#4 |
|
Posts: 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:... > 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 |
|
|
|
#5 |
|
Posts: 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 > 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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |