62,050
社区成员
发帖
与我相关
我的任务
分享
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function imgBtnUserMoveOnClick ()
{
//alert(window.event.clientX);
document.all.windowMoveing.style.left =window.event.clientX-100;
windowMoveing.style.top =window.event.clientY-80;
windowMoveing.style .display ='';
return false;
}
//隐藏
function moveCancer()
{
windowMoveing.style .display ='none';
}
</script>
..............
.................
..............
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
</asp:GridView>
<div id="windowMoveing" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; DISPLAY: none; BACKGROUND: #ffffff; BORDER-LEFT: #000000 1px solid; WIDTH: 200px; BORDER-BOTTOM: #000000 1px solid; POSITION: absolute; HEIGHT: 70px; TEXT-ALIGN: center">
GridView1_RowDataBound事件里:
btn.Attributes["onclick"] ="return imgBtnUserMoveOnClick();
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Temp.aspx.cs" Inherits="Temp" %>
<!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>无标题页</title>
<script language="javascript" type="text/javascript">
function show(obj)
{
var table=document.getElementById('GridView1');
var top=table.offsetTop+obj.offsetTop+obj.offsetHeight-2;
var left=table.offsetLeft+obj.offsetLeft+obj.offsetWidth+10;
var div=document.getElementById('detailsDiv');
div.style.display='';
div.style.top = top + "px"
div.style.left = left + "px";
div.style.backgroundColor="red";
div.focus();
}
//onload='getTime()'
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
</asp:GridView>
<div id='detailsDiv' style="position:absolute;display:none" onBlur='javascript:this.style.display="none";'>test</div>
</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 Temp : System.Web.UI.Page
{
protected ICollection CreateDataSource()
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("学生班级", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal)));
dt.Columns.Add(new System.Data.DataColumn("布尔", typeof(System.Boolean)));
for (int i = 0; i < 11; i++)
{
System.Random rd = new System.Random(Environment.TickCount * i); ;
dr = dt.NewRow();
dr[0] = "班级" + i.ToString();
dr[1] = "学生" + i.ToString();
dr[2] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[3] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[4] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[5] = System.Math.Round(rd.NextDouble() * 100, 2);
dr[6] = i % 2 == 0 ? true : false;
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = CreateDataSource();
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string str = "show(this);document.getElementById('detailsDiv').innerHTML='当前选择行是" + e.Row.RowIndex;
str += "<br>班级:" + e.Row.Cells[0].Text;
str += "<br>姓名:" + e.Row.Cells[1].Text;
str += "<br>语文:" + e.Row.Cells[2].Text;
str += "<br>数学:" + e.Row.Cells[3].Text;
str += "<br>英语:" + e.Row.Cells[4].Text;
str += "<br>计算机:" + e.Row.Cells[5].Text;
str += "';";
e.Row.Cells[1].Attributes.Add("onclick", str);
}
}
}