zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Gridview的tooltip功能

功能 GridView tooltip
2023-09-27 14:26:14 时间

gridview提供了tooltip功能,当鼠标移动到下发内容单元格时,会把所有内容都给显示出来。

效果图如下 :

 

 在具体实现上,只需要在RowDataBound事件中写上一段代码即可:

 protected void GridViewEx_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
        if (e.Row.Cells[8].Text.Length > 35)
        {
           e.Row.Cells[8].ToolTip = e.Row.Cells[8].Text;
           e.Row.Cells[8].Text = e.Row.Cells[8].Text.Substring(0, 35) + "...";
        }
    }
 }