如何在鼠标悬停的gridview行中显示工具提示文本?

问题描述:

我需要在gridview行的mousehover上显示工具提示。我有复选框作为模板字段。当复选框被禁用时,我想显示这个工具提示。 下面是在GridView rowdataboud如何在鼠标悬停的gridview行中显示工具提示文本?

if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       string State = (e.Row.Cells[a].Text).ToString(); 
       foreach (TableCell cell in e.Row.Cells) 
       { 
        if (State == "Y") 
        { 
         cell.BackColor = Color.Gray; 
         e.Row.Attributes.Add("onmouseover", "alert('This data is reserved');"); 

        } 
       } 
      } 

这里,而不是显示警告框,我想显示工具提示。

尝试设置title属性为:

e.Row.Attributes.Add("title", "This data is reserved"); 

这会显示默认的样式提示当鼠标移动到行,但是,您可能想考虑jQuery UI tooltip plugin

你只需要与对其进行初始化元素,例如,下面的代码将初始化并配置整个文档的Tooltip插件:

<script src="Scripts/jquery-2.0.0.min.js"></script> 
<script src="Scripts/jquery-ui-1.12.1.min.js"></script> 
<link href="Content/themes/base/all.css" rel="stylesheet" /> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $(document).tooltip(); 
    }); 
</script>