Hello, I am working in VS.NET 2003 with the original datagrid control. There does not appear to be a published technique for displaying alt text on the grid headers (e.g. mouseover causes a pop-up explaining what the column represents).

Has anyone successfully accomplished this with the Microsoft datagrid or a third party?

Thank you in advance!

For IE, I think setting the title attribute will do that. I'm pretty sure that this does not work on Firefox however.

Inherit from BoundColumn and DataGrid classes. Add a public string accessor for the tool tip text in the BoundColumn derived class. Override the OnItemCreated event in your derived DataGrid class. My company is Weblogik so we prefix all our derived classes wl, so you might want to change that.

using System;
using System.Web.UI.WebControls;

namespace yourproject.namespace
{
	/// <summary>
	/// Summary description for wlBoundColumn.
	/// </summary>
	public class wlBoundColumn : BoundColumn
	{
		private string headerToolTip;
		public string HeaderToolTip
		{
			get{return headerToolTip;}
			set{headerToolTip = value;}
		}
	}

	/// <summary>
	/// Summary description for wlDataGrid.
	/// </summary>
	public class wlDataGrid : DataGrid 
	{
		private const string HEADER_TOOLTIP_FORMAT = @"<p title=""{0}"">{1}</p>";

		protected override void OnItemCreated(DataGridItemEventArgs e)
		{
			if(e.Item.ItemType == ListItemType.Header) 
			{ 
				for (int i=0;i < e.Item.Cells.Count;i++) 
				{ 
					if (Columns[i] is wlBoundColumn) 
					{ 
						wlBoundColumn col = (wlBoundColumn)Columns[i]; 
						if (col.HeaderToolTip != null) 
						{ 
							TableCell cell = e.Item.Cells[i]; cell.Text = String.Format(HEADER_TOOLTIP_FORMAT,
																  col.HeaderToolTip,cell.Text);
						}
					}    
				}
			}
			//invoke base class method 
			base.OnItemCreated(e);
		}
	}
}

In your aspx page you need to register a TagPrefix:

<% @Page blah... %>
<%@ Register TagPrefix="wlc" Namespace="yourproject.namespace" Assembly="yourprojectassemblyname" %>

<DOCTYPE Blah ...>

<html>
<body>
<form>

<wlc:wlDataGrid id="wlDataGrid1" runat="server" AutoGenerateColumns="False">
	<columns>
		<wlc:BoundColumn DataField="fieldname" HeaderText="header" HeaderToolTip="My header tooltip"></wlc:wlBoundColumn>
	</columns>
</wlc:wlDataGrid>

.
.
.

I have found this works in FireFox (1.5 tested, I haven't tried 2.0), but there seems a strange behaviour, if you 'view page source' it stops working properly afterwards. I don't know if that has anything to do with the page being in a pop-up child window.

Hello, Infarction-- There is no title attribute in the DataGrid control. I've checked .NET 1.1, 2.0, and 3.5.

Hello, Paul-- I'm finally getting to this. The derived class compiles without errors, I added a line the aspx to register the new TagPrefix, but now I get The directive is missing a 'src' attribute.

Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.