GridView鼠标悬停弹出层

ToolTip.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ToolTip.aspx.cs" Inherits="ToolTip" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>ToolTip</title>
  6. </head>
  7. <script language="javascript">
  8.     function Show(qusetion, answer, email)
  9.     {
  10.         document.getElementById("td1").innerText="问题:" + qusetion;
  11.         document.getElementById("td2").innerText="答案:" + answer;
  12.         document.getElementById("td3").innerText="邮箱:" + email;
  13.         x = event.clientX + document.body.scrollLeft;
  14.         y = event.clientY + document.body.scrollTop + 30;
  15.         div1.style.display="block";
  16.         div1.style.left = x;
  17.         div1.style.top = y;                
  18.     }
  19.     function Hide()
  20.     {
  21.         div1.style.display="none";
  22.     }
  23. </script>
  24. <body>
  25. <form id="form1" runat="server">
  26. <div id="div1" style="display:none; position:absolute">
  27. <table border="0" cellpadding="0" bgcolor="#6699ff">
  28.   <tr>
  29.     <td width="180px" style="color:White">信息<hr /></td>
  30.   </tr>
  31.   <tr>
  32.     <td id="td1" height="25px" style="color:White"></td>
  33.   </tr>
  34.   <tr>
  35.     <td id="td2" height="25px" style="color:White"></td>
  36.   </tr>
  37.   <tr>
  38.     <td id="td3" height="25px" style="color:White"></td>
  39.   </tr>
  40. </table>
  41. </div>
  42. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Size="11pt" OnRowDataBound="GridView1_RowDataBound">
  43.     <Columns>
  44.         <asp:TemplateField HeaderText="用户ID" InsertVisible="False" SortExpression="ID">
  45.             <ItemTemplate>
  46.                 <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
  47.             </ItemTemplate>
  48.             <HeaderStyle BackColor="Blue" ForeColor="White" />
  49.         </asp:TemplateField>
  50.         <asp:TemplateField HeaderText="用户名" SortExpression="Uname">
  51.             <ItemTemplate>
  52.                 <asp:Label ID="Label2" runat="server" Text='<%# Bind("Uname") %>'></asp:Label>
  53.             </ItemTemplate>
  54.             <HeaderStyle BackColor="Blue" ForeColor="White" />
  55.         </asp:TemplateField>
  56.     </Columns>
  57. </asp:GridView>
  58. </form>
  59. </body>
  60. </html>

 

ToolTip.aspx.cs

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class ToolTip : System.Web.UI.Page
  13. {
  14.     private DataTable dt;
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         if (!IsPostBack)
  18.         {
  19.             string sql = "SELECT * FROM [Utest]";
  20.             DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, sql);
  21.             dt = new DataTable();
  22.             dt = ds.Tables[0];
  23.             GridView1.DataSource = dt;
  24.             GridView1.DataBind();
  25.         }
  26.     }
  27.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  28.     {
  29.         if (e.Row.RowType == DataControlRowType.DataRow)
  30.         {
  31.             Label lab = e.Row.FindControl("Label2"as Label;
  32.             lab.Attributes.Add("onmousemove""Show('" + dt.Rows[e.Row.RowIndex]["Uquestion"].ToString() + "', '" + dt.Rows[e.Row.RowIndex]["Uanswer"].ToString() + "', '" + dt.Rows[e.Row.RowIndex]["Uemail"].ToString() + "')");
  33.             lab.Attributes.Add("onmouseout""Hide();");
  34.         }
  35.     }
  36. }
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值