• 为gridview的每个单元格添加鼠标悬停提示文本(tooltip)


    为gridview的每个单元格添加鼠标悬停提示文本(tooltip)!

    gridview编译到客户端是table,tooltip属性被编译成title属性。于是,我就在gridview的RowDataBound事件里写下如下代码:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

        {

            for (int i = 0; i < e.Row.Cells.Count; i++)//获取总列数

            {

                //如果是数据行则添加title

                if (e.Row.RowType ==DataControlRowType.DataRow )

                {//设置title为gridview的head的text

                    e.Row.Cells[i].Attributes.Add("title", GridView1.HeaderRow.Cells[i].Text.ToString().Trim());

                }

            }

        }

    注:

    如果gridview有buttonfield并且你想为此列的每个单元格也设置提示功能,你需要对上面的代码稍加修改。

    思路:如果你很懒,你应该把buttonfield的headtext设置为空("")。如果你确实想设置鼠标悬停提示,你可一让title的值为单元格本身的内容,但是在这之前,必须要判断下单元格是不是数据单元格或者说是不是buttonfield。

  • 相关阅读:
    (easy)LeetCode 223.Rectangle Area
    (easy)LeetCode 205.Reverse Linked List
    (easy)LeetCode 205.Isomorphic Strings (*)
    (easy)LeetCode 204.Count Primes
    (easy)LeetCode 203.Remove Linked List Elements
    (easy)LeetCode 202.Happy Number
    (easy)LeetCode 198.House Robber
    (easy)LeetCode 191.Number of 1 Bits
    试题分析
    使用ADO.NET访问数据库
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/1893876.html
Copyright © 2020-2023  润新知