How to show tooltip in gridview?


Here are some few steps to do this fuctionality

Step 1. Take one gridview control

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;

<html xmlns=””&gt;
<head runat=”server”>
<form id=”form1″ runat=”server”>
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”
<asp:TemplateField HeaderText=”Id”>
<%#Container.DataItemIndex+1 %>
<asp:BoundField HeaderText=”Description1″  DataField=”Desc1″ >
<ItemStyle Font-Bold=”True” Font-Italic=”True”
ForeColor=”#FF3300″ />


Step 2. Click on RowDataBound event of Gridview and write this code in code behind file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
SqlConnection con = new SqlConnection(“Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True”);
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)


private void FillGrid()
SqlDataAdapter da = new SqlDataAdapter(“Select *from tblStory”, con);
DataTable dt = new DataTable();
GridView1.DataSource = dt;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
ViewState[“Data”] = e.Row.Cells[1].Text;
if (e.Row.Cells[1].Text.Length > 25)
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 25) + “…”;
e.Row.Cells[1].ToolTip = ViewState[“Data”].ToString();

Then you will get output like this


2 thoughts on “How to show tooltip in gridview?

  1. Happy February 21, 2012 / 5:21 am


    This information is quite useful

    thanks a lot……………….for posting…..

    • Chandra Dev February 22, 2012 / 2:05 am

      I m glad to know that you liked my artical.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.