Label 隨 滑鼠移動顯示Gridview資料。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); DataColumn dc = new DataColumn("A"); dt.Columns.Add(dc); dc = new DataColumn("B"); dt.Columns.Add(dc); dc = new DataColumn("C"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr[0] = "1"; dr[1] = "王小明"; dr[2] = "99"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "2"; dr[1] = "張三"; dr[2] = "56"; dt.Rows.Add(dr); this.GridView1.DataSource = dt; this.GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[1].Attributes["onmouseover"] = "document.getElementById('" + Label1.ClientID + "').innerHTML = '" + e.Row.Cells[1].Text + "';"; } } }