ToolTip.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ToolTip.aspx.cs" Inherits="ToolTip" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>ToolTip</title>
- </head>
- <script language="javascript">
- function Show(qusetion, answer, email)
- {
- document.getElementById("td1").innerText="问题:" + qusetion;
- document.getElementById("td2").innerText="答案:" + answer;
- document.getElementById("td3").innerText="邮箱:" + email;
- x = event.clientX + document.body.scrollLeft;
- y = event.clientY + document.body.scrollTop + 30;
- div1.style.display="block";
- div1.style.left = x;
- div1.style.top = y;
- }
- function Hide()
- {
- div1.style.display="none";
- }
- </script>
- <body>
- <form id="form1" runat="server">
- <div id="div1" style="display:none; position:absolute">
- <table border="0" cellpadding="0" bgcolor="#6699ff">
- <tr>
- <td width="180px" style="color:White">信息<hr /></td>
- </tr>
- <tr>
- <td id="td1" height="25px" style="color:White"></td>
- </tr>
- <tr>
- <td id="td2" height="25px" style="color:White"></td>
- </tr>
- <tr>
- <td id="td3" height="25px" style="color:White"></td>
- </tr>
- </table>
- </div>
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Size="11pt" OnRowDataBound="GridView1_RowDataBound">
- <Columns>
- <asp:TemplateField HeaderText="用户ID" InsertVisible="False" SortExpression="ID">
- <ItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
- </ItemTemplate>
- <HeaderStyle BackColor="Blue" ForeColor="White" />
- </asp:TemplateField>
- <asp:TemplateField HeaderText="用户名" SortExpression="Uname">
- <ItemTemplate>
- <asp:Label ID="Label2" runat="server" Text='<%# Bind("Uname") %>'></asp:Label>
- </ItemTemplate>
- <HeaderStyle BackColor="Blue" ForeColor="White" />
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
- </form>
- </body>
- </html>
ToolTip.aspx.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class ToolTip : System.Web.UI.Page
- {
- private DataTable dt;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- string sql = "SELECT * FROM [Utest]";
- DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, sql);
- dt = new DataTable();
- dt = ds.Tables[0];
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- Label lab = e.Row.FindControl("Label2") as Label;
- 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() + "')");
- lab.Attributes.Add("onmouseout", "Hide();");
- }
- }
- }