【问题标题】:gridView definitions for Column headings with mouse hover带有鼠标悬停的列标题的 gridView 定义
【发布时间】:2013-12-13 18:32:07
【问题描述】:

我有一个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 ";
        }

    }

但是,当我将鼠标指针悬停在上面时,我看不到任何文字。网格视图本身工作正常。

谁能帮忙?

【问题讨论】:

    标签: c# javascript html asp.net gridview


    【解决方案1】:

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

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

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

    这是我测试您的代码的方法

    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 ";
        }
    }
    

    【讨论】:

    • 我知道伙计。工具提示适用于我的其他网格视图,但不适用于这个相同的方法,只是名称不同。添加属性也不起作用。词穷了。
    • 我在工具提示和代码的添加属性部分添加了断点。这些断点永远不会被命中。而在我的另一个 gridview 上,相同类型的编码的断点在页面加载时被命中。我的代码在服务器端看不到 gridview 吗?
    • 看起来您没有将 gvwAccums_RowDataBound 事件附加到 gvwAccum。例如,&lt;asp:GridView ID="gvwAccums" ... OnRowDataBound="gvwAccums_RowDataBound" &gt;
    • ahhhhhhhhhhhhhh 抓拍
    猜你喜欢
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 2015-03-27
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    相关资源
    最近更新 更多