如何在网格视图列标题上添加鼠标悬停工具提示

Jan*_*net 8 asp.net gridview

当用户将鼠标悬停在gridview中列的列标题上时,例如:列标题年份,当我将鼠标悬停在年份上时,我应该看到该年份的含义的解释"这是学生加入大学等的那一年".

下面是我的ascx代码:

 <asp:GridView ID="grdView" runat="server" Width="900px" AutoGenerateColumns="False"
                AllowPaging="true" AllowSorting="true" CellSpacing="0" CellPadding="5" PageSize="20"
        OnRowDataBound="grdView_RowDataBound">
                <Columns>
 <asp:TemplateField HeaderText="ID Number" ItemStyle-Width="90px" >
    <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID")%'></asp:Label>
    </ItemTemplate>
 </asp:TemplateField><asp:BoundField DataField="StudentName" HeaderText="StudentName"> </asp:BoundField>
Run Code Online (Sandbox Code Playgroud)

请告诉我如何将鼠标悬停在我的gridview列标题上的文本或工具提示上.谢谢,

小智 8

这是使用Jquery在C#中使用Gridview的CSS工具提示

protected void grd_popup_details_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
            e.Row.Cells[i].ToolTip = e.Row.Cells[i].Text;
        }
    }
Run Code Online (Sandbox Code Playgroud)

参考链接


Pet*_*vic 6

我从来没有做过任何asp.net开发,但这里似乎提供了一个解决方案:如何在ASP.NET中的gridview中为每个标题列添加标题

你的样本看起来像这样:

 <asp:GridView ID="grdView" runat="server" Width="900px" AutoGenerateColumns="False"
            AllowPaging="true" AllowSorting="true" CellSpacing="0" CellPadding="5" PageSize="20"
    OnRowDataBound="grdView_RowDataBound">
            <Columns>
 <asp:TemplateField HeaderText="ID Number" ItemStyle-Width="90px" >
<HeaderTemplate>
       <asp:Label ID="Header" ToolTip="HERE WE GO!!!!" runat="server" Text="Label"></asp:Label>
       </HeaderTemplate>
    <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID")%'></asp:Label>
    </ItemTemplate>
 </asp:TemplateField><asp:BoundField DataField="StudentName" HeaderText="StudentName"> </asp:BoundField>
Run Code Online (Sandbox Code Playgroud)

我会尝试一下:)


小智 5

在您的代码中,为GridView创建方法rowDataBound并添加以下代码

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        foreach (TableCell cell in e.Row.Cells)
        {
            cell.Attributes.Add("title", "Tooltip text for " + cell.Text);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

不要忘记在GridView中设置属性OnRowDataBound.

http://rosshawkins.net/archive/2007/04/15/adding-tooltips-to-gridview-headers.html.aspx