473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Nov 18 '05 #1
4 3333
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will | last post by:
In a Windows form: I need the code to manually set the header name of a column in a datagrid to anything i want. Everytime i retieve records from a database, the coloum header of the datagrid...
0
by: Cliff Benoist | last post by:
I have a case where I would like to add a textbox to a datagrid column header. I would like to use a user control or custom control to create a reusable control. The textbox will filter the...
0
by: amber | last post by:
Okay, there is some wierdness going on with my datagrid... I'm trying to make my column header 2 lines high. If I go into the Form - InitializeComponent code, and change the line: ...
3
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is...
0
by: VMI | last post by:
My Windows datagrid has two columns: one with the data that the user will see (col_X) and the other one (a hidden one: col_sort) that'll be used to sort data. When a user clicks on col_X's column...
0
by: Demetri | last post by:
I have a web form with a datagrid. The datagrid has 5 columns. In design mode each column has header text. I defined the header text, data source, etc in property builder (visible is checked in...
1
by: Leo | last post by:
Can someone tell me how to make the sorting triangle on datagrid column header always show up? And which property can change the color of the triangle ? The default color is white. Thanks
1
by: charvi | last post by:
Hi i am doing project in vb.net 2003 i have a form which contains a datagrid.This datagrid is used to view the contents of table and is working properly.here column header caption will be same as...
3
by: lucindaa | last post by:
How to set row values as Datagrid Column Header? Please any help me
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.