<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="NET_Default" %> <!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>鼠标划过显示Div层,Div层里面的信息从数据库中取出</title> <mce:script type="text/javascript"><!-- function showTip(oEvent,obj){ var oDiv = document.getElementById("divTip1"); NET_Default.ReturnTable(obj,callback); oDiv.style.visibility="visible"; oDiv.style.left = oEvent.clientX-25; oDiv.style.top =oEvent.clientY-35; } function hideTip(oEvent){ var oDiv = document.getElementById("divTip1"); oDiv.style.visibility = "hidden"; } function callback(res) { if(res!=null) { document.getElementById("divTip1").innerHTML=res.value; } } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <table> <tr> <td>姓名</td> <td οnmοuseοver="showTip(event,'<%#Eval("UserName") %>')" οnmοuseοut="hideTip(event)"><%#Eval("UserName") %></td> </tr> </table> </ItemTemplate> </asp:DataList> <div id="divTip1" style="background:yellow; position:absolute; visibility:hidden; padding: 5px" mce_style="background:yellow; position:absolute; visibility:hidden; padding: 5px"> </div> </form> </body> </html> 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; public partial class NET_Default : System.Web.UI.Page { DataTable DT = new DataTable(); DataColumn DC = new DataColumn(); DataRow DR; protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(NET_Default)); if (!Page.IsPostBack) { CreateDataTable(); for (int i = 0; i < 3; i++) { DR = DT.NewRow(); DR["ID"] = i.ToString(); DR["UserName"] ="胡果" + i.ToString(); DR["Keyword"] = "欢迎你ws_hgo" + i.ToString(); DT.Rows.Add(DR); } } DataList1.DataSource = DT; DataList1.DataBind(); } public void CreateDataTable() { DC = new DataColumn(); DC.ColumnName = "ID"; DC.DataType = System.Type.GetType("System.Int32"); //DC = new DataColumn("ID", System.Type.GetType("System.Int32")); DT.Columns.Add(DC); DC = new DataColumn(); DC.ColumnName = "UserName"; DC.DataType = System.Type.GetType("System.String"); DT.Columns.Add(DC); DC = new DataColumn(); DC.ColumnName = "Keyword"; DC.DataType = System.Type.GetType("System.String"); DT.Columns.Add(DC); } [AjaxPro.AjaxMethod] public string ReturnTable(string Name) { string res; //我这里有数组代替 string[] str = new string[] { "胡果0", "胡果1", "胡果2" }; if (Array.IndexOf<string>(str, Name) != -1) { res = "欢迎大家来到" + Name.Substring(0,Name.Length-1).ToString() + "http://blog.csdn.net/ws_hgo"; } else { res = "无!"; } return res; } }