Monday, June 30, 2008

Tooltip in ASP.NET GridView headers

I was searching for the way show Tooltips for headers of ASP.NET GridView control without using javascript or using unnecessary overhead in code. And I found the way how to do it. When you define columns or your GridView you should use TemplateField instead of BoundField cause it's customizable. In TemplateField you can define HeaderTemplate and put there Label control with needed Tooltip. Here is the code:

<asp:GridView ID="GridView" DataSourceID="ObjectDataSource1" runat="server" AutoGenerateColumns="False" >
<asp:TemplateField SortExpression="ShareCount">
<asp:Label runat="server" Text="Nr. of Stocks" ToolTip="Total number of stocks on the market"></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ShareCount") %>'></asp:Label>

1 comment:

Rem said...

Your blog is very nice...
visit my blog example