aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to show the tooltip for gridview header columns using

May 28, 2011

Here I will explain how to show the tooltip for gridview header columns using


In previous article I explained clearly how to show tooltip for gridview rows and columns and in another post I explained clearly show up and down arrows for gridview sorting . Now I will explain how to show tooltip for gridview headers using with slight code modification using above posts. To display tooltip for gridview header first design your aspx code like this

<html xmlns="">
<head id="Head1" runat="server">
<title>Show Tooltip for Gridview Header</title>
<form id="form1" runat="server">
<asp:GridView runat="server" ID="gvdetails" DataSourceID="dsdetails" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" onrowdatabound="gvdetails_RowDataBound">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:SqlDataSource ID="dsdetails" runat="server" ConnectionString="<%$ConnectionStrings:dbconnection %>"
SelectCommand="select * from UserInformation"/>
Here don’t forgot to set the connection string in web.config file here I am getting database connection from web.config file for that reason you need to set the connectionstring in web.config file like this

<add name="dbconnection" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"/>

In code behind gridview RowDataBound event write following code to display tooltip for gridview headers.

C#.NET Code

protected void gvdetails_RowDataBound(object sender, GridViewRowEventArgs e)
//This condition is used to check RowType is Header
for (int i = 0; i < gvdetails.Columns.Count; i++)
e.Row.Cells[i].ToolTip = gvdetails.Columns[i].HeaderText;


  Protected Sub gvdetails_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        'This condition is used to check RowType is Header
        If e.Row.RowType = DataControlRowType.Header Then
            For i As Integer = 0 To gvdetails.Columns.Count - 1
                e.Row.Cells(i).ToolTip = gvdetails.Columns(i).HeaderText
        End If
    End Sub

If you observe codebehind code I am displaying gridview tooltips based HeaderText if you want to display tooltip based on SortExpression then change this line

e.Row.Cells[i].ToolTip = gvdetails.Columns[i].HeaderText;


e.Row.Cells[i].ToolTip = gvdetails.Columns[i].SortExpression;

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...


BA said...

The far easier way to do this is by using a TemplateField instead of a BoundField.

BA said...

see this page for an example

BA said...

ugh, annoying, my link didn't get posted. Let's try this again, here's the site:

Also your link at the top "how to show tooltip for gridview rows and columns" is going to the wrong page.

Anonymous said...

its very helpful for freshers to

Anonymous said...

i tried.its vely helpful. Great.good post. Thank you.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.