Blog

Showing tooltip on header columns of a GridView

Posted by Rishikesh Kumar Singh Blogs | ASP.NET Programming Jan 03, 2013
Here I am going to explain how to show the tooltip on the columns of header in 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;
        }
    }
}
COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
Employers - Post Free Jobs
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.