天天看点

Gridview中当鼠标经过数据行时弹出一个层显示数据

  JS代码 页面源码 后台源码 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { databind(); } } public void databind() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrin gs["Conn"].ToString()); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "Select top 10 * From Customers"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); this.GridView1.DataSource = ds.Tables[0]; this.GridView1.DataKeyNames = new string[] { "CustomerID" }; this.GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "Test('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + e.Row.Attributes.Add("onmouseout", "Hide()"); } }