Re: How to display images in datagrid column header?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Craig Deelsnyder (cdeelsny_at_no_spam_4_meyahoo.com)
Date: 06/14/04


Date: Mon, 14 Jun 2004 17:57:42 -0500

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-us/cpref/html/frlrfSystemWebUIWebControlsDataGridColumnClassHeaderTextTopic.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-us/cpref/html/frlrfSystemWebUIWebControlsDataGridColumnClassHeaderTextTopic.asp

-- 
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Relevant Pages

  • Re: GridView in a table
    ... Now, AFAIK, it's not "hiding" the GridView, it's being extremely percise--since the designer doesn't have a data source to render columns off of (since we're loading data in code-behind), it assumes that there isn't any data. ... asp:Table generates HTML, but, at least when I go into the designer, I can't manipulate controls inside the TableCell. ... Another here probably has more experience with that control and can provide some insight--it may be behavior by design. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Wheres the NG to complain about VS 2003 IDE?
    ... the designer creates when you sometimes switch from Design ... leaves your HTML formatting alone. ... Consider that MS is really pushing code-behind ... > I think it's the right approach to wean developers out of that classic ASP ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I get code to fire on the HTML page instead of the code behind?
    ... other, then send the page (either down to the client or back to the server), ... in my HTML how do I reference it in my code-behind ". ... Code that executes in the client is "client-side ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Asp.net 2.0 and Dreamweaver
    ... within VS.NET 2003 that do NOT have code-behind files, and I don't remember not being able to open them. ... nearly all the examples for ..NET use single files. ... code and html. ... a separate file is so you can separate the content and style from the programming. ...
    (microsoft.public.vsnet.general)
  • Re: width of column in DataGrid remains the same
    ... the width of a column in a html table (what the grid control generates), ... the width of widest column. ... > The width of the column is always set to length of the Headertext, ...
    (microsoft.public.dotnet.framework.aspnet)