c# - 带有鼠标悬停的列标题的 gridView 定义

标签 c# javascript html asp.net gridview

我有一个 gridView:-

<asp:GridView ID="gvwAccums" runat="server"
        AutoGenerateColumns="false"
        CssClass="GridView" 
        HeaderStyle-CssClass="GridViewHeaderRowStyle"
        RowStyle-CssClass="GridViewRowStyle" 
        AlternatingRowStyle-CssClass="GridViewAlternatingRowStyle"
        EmptyDataRowStyle-CssClass="GridEmptyDataRowStyle"
        >
            <Columns>
                <asp:BoundField HeaderText="Start Date" DataField="Beg_PlanYr" />
                <asp:BoundField HeaderText="Paid" DataField="indTotPaid" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
                    ItemStyle-HorizontalAlign="Right" />
                <asp:BoundField HeaderText="Copay" DataField="indTotCopay" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
                    ItemStyle-HorizontalAlign="Right" />
                <asp:BoundField HeaderText="Deductible" DataField="indTotDed" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
                    ItemStyle-HorizontalAlign="Right" />
                <asp:BoundField HeaderText="Out of Pocket" DataField="indTotOop" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
                    ItemStyle-HorizontalAlign="Right" />
            </Columns>
            <EmptyDataTemplate>
                <div id="pnlEmptyAcums" runat="server" class="NoRecs">
                    <span style="font-style: italic">No Accumulated Totals found.</span>
                </div>
            </EmptyDataTemplate>
        </asp:GridView>

我正在尝试将定义文本添加到服务器端的列标题中:-

protected void gvwAccums_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridViewRow row = e.Row;
        bool isDataRow = row.RowType == DataControlRowType.DataRow;
        TableCellCollection cells = e.Row.Cells;
        string allCells = string.Empty;
        string content = "";
        int lastCol = cells.Count - 1;

        content = cells[lastCol].Text.Trim();


        // Only do this to the header row, ignore data and footer rows. Adding definition to the label of each column on the Gridview of claims.
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].ToolTip = "xxxxx ";
            e.Row.Cells[1].ToolTip = "yyyyy ";
            e.Row.Cells[2].ToolTip = "zzzzz ";
            e.Row.Cells[3].ToolTip = "fffff ";
            e.Row.Cells[4].ToolTip = "vvvvv ";
        }

    }

但是,当我将鼠标指针悬停在上方时,我没有看到任何文本。 gridview 本身工作正常。

有人能帮忙吗?

最佳答案

您的代码对我有用 - 当鼠标悬停在标题文本上时会显示工具提示。

如果还是不行,你可以试试Attributes.Add

e.Row.Cells[0].Attributes.Add("title", "xxxxx ");

这是我如何测试你的代码

enter image description here

public class Test
{
    public int Beg_PlanYr { get; set; }
    public decimal indTotPaid { get; set; }
    public decimal indTotCopay { get; set; }
    public decimal indTotDed { get; set; }
    public decimal indTotOop { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        gvwAccums.DataSource = new List<Test>()
        {
            new Test {Beg_PlanYr = 1, indTotPaid = 1, indTotCopay = 1, indTotDed = 1, indTotOop = 1},
            new Test {Beg_PlanYr = 2, indTotPaid = 2, indTotCopay = 2, indTotDed = 2, indTotOop = 2},
            new Test {Beg_PlanYr = 3, indTotPaid = 3, indTotCopay = 3, indTotDed = 3, indTotOop = 3},
        };
        gvwAccums.DataBind();
    }
}

protected void gvwAccums_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Cells[0].ToolTip = "xxxxx ";
        e.Row.Cells[1].ToolTip = "yyyyy ";
        e.Row.Cells[2].ToolTip = "zzzzz ";
        e.Row.Cells[3].ToolTip = "fffff ";
        e.Row.Cells[4].ToolTip = "vvvvv ";
    }
}

关于c# - 带有鼠标悬停的列标题的 gridView 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20253945/

相关文章:

html - 如何在 HTML/CSS 中创建一个元素,其中包含一个矩形,其中左侧有一个半圆?

c# - 在 Visual Studio 2010 中针对不同的构建平台使用不同的引用?

c# - 在类似的 WPF 应用程序之间共享 View

c# - 截取的屏幕截图仅包含黑色像素

javascript - 在 vue.js、quasar 框架中启用复选框检查功能

html - 按钮和输入不继承正文的字体系列

c# - 无法加载文件或程序集 Microsoft.VisualStudio.Shell,版本 = 2.0.0.0

javascript - 显示以下链接的结果

javascript - Cycle2 幻灯片与轮播寻呼机不工作

html - 我怎样才能制作一本类似于这本的 HTML 电子书?