Tooltip For GridView Header..

Description:
 Here in this example I am explaining about how to show tooltip for gridview Header
Emp.aspx:

Write the following code in the aspx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Show Tooltip for Gridview Header</title>
</head>
<body>
<form id="form1" runat="server">
<div>


<asp:GridView runat="server" ID="gvEmpdetails" DataSourceID="EmpDetails" AllowPaging="True"

AllowSorting="True" AutoGenerateColumns="False" OnRowDataBound="gvEmpdetails_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" />
<Columns>
<asp:BoundField DataField="EmpName" HeaderText="EmpName" SortExpression="EmpName" />
<asp:BoundField DataField="EmpSal" HeaderText="EmpSal" SortExpression="EmpSal" />
<asp:BoundField DataField="EmpBranch" HeaderText="EmpBranch" SortExpression="EmpBranch" />
<asp:BoundField DataField="EmpCode" HeaderText="EmpCode" SortExpression="EmpCode" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="EmpDetails" runat="server" ConnectionString="<%$ ConnectionStrings:CustomerConnectionString %>"
SelectCommand="SELECT [EmpName], [EmpSal], [EmpBranch], [EmpCode] FROM [Employee]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>



Emp.aspx.cs:

In the code behind page write the Below code in the RowDataBoundEvent


  protected void gvEmpdetails_RowDataBound(object sender, GridViewRowEventArgs e)

    {
        //This condition is used to check RowType is Header
        if (e.Row.RowType == DataControlRowType.Header)
        {
            for (int i = 0; i < gvEmpdetails.Columns.Count; i++)
            {
                e.Row.Cells[i].ToolTip = gvEmpdetails.Columns[i].HeaderText;
            }
        }
    }

0 Responses to “Tooltip For GridView Header..”

Post a Comment

Labels

Topics