如何为每个gridview行设置'mouseover'事件? [英] How to set 'mouseover' event for per gridview row?

查看:81
本文介绍了如何为每个gridview行设置'mouseover'事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在使用ASP.NET(C#)。我设计了一个gridview并从数据库(SQL Server)加载数据。没关系。



这是先进的要求:

- >数据库包含调试时无法显示的字段。因为我写道:

 <   asp:BoundField     DataField   = < span class =code-keyword> course_group    HeaderText   = 课程组    SortExpression   =  course_group    HeaderStyle-CssClass   =  hidden    ItemStyle-CssClass   =  hidden    /  >  



in css:

 hidden  
{
显示 无;
}



- >现在,我想得到 course_group 的值,并将其设置为gridview行作为工具提示。像这样:

 <   a     href   =  http://www.w3schools.com    title   = 我是工具提示 > 访问W3Schools.com!<   / a  >  



我知道编写链接工具提示的方法,但不是 gridview row tooltip



我觉得这很困难,因为你可能想要为所有 gridview行 提供许多不同的工具提示文本 >


有没有这样做?

你能给我任何C#代码解决方案(鼠标悬停事件)或CSS / Javascript代码解决方案(悬停事件)?

解决方案

我认为您不需要额外的 BoundField 对于相同的。您可以将工具提示附加到 RowDataBound 事件中的行。这样的事情...

 受保护  void  gvTestEscapePress_RowDataBound( object  sender,GridViewRowEventArgs e)
{
if (e .Row.RowType == DataControlRowType.DataRow)
{
// 这里得到的数据列course_group并将其分配给下面的工具提示。
string course_group = 演示文字;
e.Row.ToolTip = course_group;
}
}



如果这不起作用,您可以尝试添加 mouseover 事件喜欢......

 e.Row.Attributes.Add(  onmouseover,e.Row.ToolTip =   demo text); 


Hi. I'm using ASP.NET (C#). I have designed a gridview and loaded data from database (SQL Server). That's ok.

Here is advanced requirement:
-> The database contains a field that it cannot be showed while debugging. Because I had wrote:

<asp:BoundField DataField="course_group" HeaderText="Course group" SortExpression="course_group" HeaderStyle-CssClass="hidden" ItemStyle-CssClass="hidden" />


In css:

.hidden
{
display: none;
}


-> Now, I wanna get the value of course_group and set it into gridview row as a "Tooltip". Like this:

<a href="http://www.w3schools.com" title="I'm a tooltip">Visit W3Schools.com!</a>


I know the way to write a link tooltip, but not for gridview row tooltip.

I think it's difficult, because you might want to many different tooltip text for all gridview rows

Is there anyway to do that?
Can you give me any C# code behind solution (mouseover event) or CSS/Javascript code solution (hover event)?

解决方案

I don't think you need a extra BoundField for the same. You can attach the tooltip to the row inside the RowDataBound Event. Something like this...

protected void gvTestEscapePress_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Here get the data of column course_group and assign it to the tooltip below.
        string course_group = "demo text";
        e.Row.ToolTip = course_group;
    }
}


If this does not work, you can try adding mouseover event like...

e.Row.Attributes.Add("onmouseover",  e.Row.ToolTip = "demo text");


这篇关于如何为每个gridview行设置'mouseover'事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆