Dzwebs.Net

撰写电脑技术杂文十余年

利用GridView的RowDataBound事件显示ToolTip

Admin | 2014-7-27 8:58:05 | 被阅次数 | 4691

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  使用GridView控件,当数据显示的时候,如果哪个单元格即字段显示的内容很多,那么,我们就可以让其只显示一部分标题。

  而当鼠标移动到该行的某列的时候,就出现完整的内容,这如何来实现呢?

  注意哦,在CS代码中,你得添加下面的事件及程序代码。

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
   if (e.Row.RowType == DataControlRowType.DataRow)
   {

            //设置试题内容列显示部分内容,鼠标移到上面显示全部内容;
    if (e.Row.Cells[6].Text.Length > 18)
    {
                e.Row.Cells[6].ToolTip = e.Row.Cells[6].Text;
                e.Row.Cells[6].Text = e.Row.Cells[6].Text.Substring(0, 18) + "";
    }
   }
  }

  其中,这两行就是关键的功能代码了

  e.Row.Cells[6].ToolTip = e.Row.Cells[6].Text;
  e.Row.Cells[6].Text = e.Row.Cells[6].Text.Substring(0, 18) + "";

  最后,你也别忘记了,在HTML代码中,要给控件添加事件名称,如下:

  <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" ……


该杂文来自: 网站开发杂文

上一篇:Close()方法 Dispose()方法 区别

下一篇:RadioButtonList与JS 取值赋值

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计