Showing tooltip on header columns of a GridView

Step-1  (Add the following code to your  Default.aspx page)

<asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound"
         AutoGenerateColumns="False" CellPadding="4">
         <RowStyle BackColor="Beige" ForeColor="#333333" HorizontalAlign="Center" Font-Bold="true"/>
                    
         <Columns>
             <asp:BoundField DataField="TYPE" HeaderText="Type" />
             <asp:BoundField DataField="CHANNEL" HeaderText="Chanel" />
             <asp:BoundField DataField="CALLERID" HeaderText="Caller ID" />
                        
             <asp:BoundField DataField="RINGING_TIME" HeaderText="RingDuration" />
             <asp:BoundField DataField="DURATION" HeaderText="CallDuration" />
         </Columns>
</asp:GridView>

Step-2.  On the RowDataBound we need to check the type of the row and if it is found to be the header then assign the text for the tooltip to the cell of that particular header.So, what we need to write on the RowDataBound is as undermentioned:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType==DataControlRowType.Header) // checking out that whether the row is a header
    {
        for (int i = 0; i < GridView1.Columns.Count; i++)
        {
            e.Row.Cells[i].ToolTip = GridView1.Columns[i].HeaderText;
        }
    }
}
Ebook Download
View all
Learn
View all