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;
        }
    }
}
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts