zoukankan
html css js c++ java
DataGrid实现tooltip功能
1.html
<
html
>
<
head
>
<
title
>
DataGridTooltip
</
title
>
<
meta
name
="GENERATOR"
content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
="CODE_LANGUAGE"
content
="C#"
>
<
meta
name
="vs_defaultClientScript"
content
="JavaScript"
>
<
meta
name
="vs_targetSchema"
content
="http://schemas.microsoft.com/intellisense/ie5"
>
<
style
type
="text/css"
>
.transparent
{
}
{}
{
}
{
BORDER-RIGHT
:
indianred 1px solid
;
BORDER-TOP
:
indianred 1px solid
;
DISPLAY
:
none
;
FILTER
:
alpha(opacity=85)
;
BORDER-LEFT
:
indianred 1px solid
;
BORDER-BOTTOM
:
indianred 1px solid
;
POSITION
:
absolute
;
BACKGROUND-COLOR
:
infobackground
}
</
style
>
<
script
language
="javascript"
>
function
Show(Country, City, Address, PostalCode, Phone, Fax)
{
//
debugger;
document.getElementById(
"
td1
"
).innerText
=
"
国家:
"
+
Country;
document.getElementById(
"
td2
"
).innerText
=
"
城市:
"
+
City;
document.getElementById(
"
td3
"
).innerText
=
"
地址:
"
+
Address;
document.getElementById(
"
td4
"
).innerText
=
"
邮编:
"
+
PostalCode;
document.getElementById(
"
td5
"
).innerText
=
"
电话:
"
+
Phone;
document.getElementById(
"
td6
"
).innerText
=
"
传真:
"
+
Fax;
x
=
event.clientX
+
document.body.scrollLeft;
y
=
event.clientY
+
document.body.scrollTop
+
20
;
Popup.style.display
=
"
block
"
;
Popup.style.left
=
x;
Popup.style.top
=
y;
}
function
Hide()
{
Popup.style.display
=
"
none
"
;
}
</
script
>
</
head
>
<
body
ms_positioning
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
div
id
="Popup"
class
="transparent"
>
<
table
border
="0"
cellpadding
="0"
bgcolor
="#00ccff"
>
<
tr
>
<
td
align
="center"
bgcolor
="indianred"
>
<
font
color
="white"
>
联系方式
</
font
></
td
>
</
tr
>
<
tr
>
<
td
id
="td1"
>
</
td
>
</
tr
>
<
tr
>
<
td
id
="td2"
>
</
td
>
</
tr
>
<
tr
>
<
td
id
="td3"
>
</
td
>
</
tr
>
<
tr
>
<
td
id
="td4"
>
</
td
>
</
tr
>
<
tr
>
<
td
id
="td5"
>
</
td
>
</
tr
>
<
tr
>
<
td
id
="td6"
>
</
td
>
</
tr
>
</
table
>
</
div
>
<
asp:DataGrid
ID
="DataGrid1"
runat
="server"
>
<
FooterStyle
ForeColor
="#003399"
BackColor
="#99CCCC"
></
FooterStyle
>
<
SelectedItemStyle
Font-Bold
="True"
ForeColor
="#CCFF99"
BackColor
="#009999"
></
SelectedItemStyle
>
<
ItemStyle
ForeColor
="#003399"
BackColor
="White"
></
ItemStyle
>
<
HeaderStyle
Font-Bold
="True"
ForeColor
="#CCCCFF"
BackColor
="#003399"
></
HeaderStyle
>
<
PagerStyle
HorizontalAlign
="Left"
ForeColor
="#003399"
BackColor
="#99CCCC"
Mode
="NumericPages"
>
</
PagerStyle
>
</
asp:DataGrid
>
</
form
>
</
body
>
</
html
>
2.cs
public
class
DataGridTooltip : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.DataGrid DataGrid1;
private
DataTable dt;
Page_Load
Page_Load
#region
Page_Load
private
void
Page_Load(
object
sender, System.EventArgs e)
{
if
(
!
IsPostBack)
{
SqlConnection cnn
=
new
SqlConnection();
cnn.ConnectionString
=
"
data source=meng;initial catalog=Northwind;password=sa;persist security info=True;user id=sa;packet size=4096
"
;
string
sqlstr
=
"
select Top 16 CustomerID, CompanyName,ContactTitle,Country, City, Address,PostalCode,Phone,Fax from Customers
"
;
cnn.Open();
SqlDataAdapter ad
=
new
SqlDataAdapter(sqlstr,cnn);
dt
=
new
DataTable();
ad.Fill(dt);
DataGrid1.DataSource
=
dt;
DataGrid1.DataBind();
}
}
#endregion
DataGrid1_ItemDataBound
DataGrid1_ItemDataBound
#region
DataGrid1_ItemDataBound
private
void
DataGrid1_ItemDataBound(
object
sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if
(e.Item.ItemType
==
ListItemType.AlternatingItem
||
e.Item.ItemType
==
ListItemType.Item)
{
e.Item.Attributes.Add(
"
onmouseover
"
,
"
this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF';
"
);
e.Item.Attributes.Add(
"
onmousemove
"
,
"
Show('
"
+
dt.Rows[e.Item.ItemIndex][
"
country
"
].ToString()
+
"
','
"
+
dt.Rows[e.Item.ItemIndex][
"
City
"
].ToString()
+
"
','
"
+
dt.Rows[e.Item.ItemIndex][
"
Address
"
].ToString()
+
"
','
"
+
dt.Rows[e.Item.ItemIndex][
"
PostalCode
"
].ToString()
+
"
','
"
+
dt.Rows[e.Item.ItemIndex][
"
Phone
"
].ToString()
+
"
','
"
+
dt.Rows[e.Item.ItemIndex][
"
Fax
"
].ToString()
+
"
');
"
);
e.Item.Attributes.Add(
"
onmouseout
"
,
"
this.style.backgroundColor=this.oldcolor;Hide();
"
);
}
}
#endregion
Web Form Designer generated code
Web Form Designer generated code
#region
Web Form Designer generated code
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base
.OnInit(e);
}
/**/
/**/
/**/
///
<summary>
///
Required method for Designer support - do not modify
///
the contents of this method with the code editor.
///
</summary>
private
void
InitializeComponent()
{
this
.DataGrid1.ItemDataBound
+=
new
System.Web.UI.WebControls.DataGridItemEventHandler(
this
.DataGrid1_ItemDataBound);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
查看全文
相关阅读:
OpenCV程序在生产环境中运行
C#调用C++导出(dllexport)方法
IIS7.5 GZip配置
wcf学习笔记--初识wcf
Greenplum installation guide
Cloudera 5.8.2 Installation guide
WPF DataGrid 合并单元格
wpf DataGrid CheckBox列全选
WPF button 圆角制作
WPF passwordbox 圆角制作
原文地址:https://www.cnblogs.com/puke/p/773145.html
最新文章
Katalon Studio有关的一些项目设置(转载)
Katalon 学习笔记(一)(转载)
web测试通用要点大全(Web Application Testing Checklist)(转载)
Android 开发知识体系
mysql中You can’t specify target table for update in FROM clause错误解决方法
常用域名记录解释:A记录、MX记录、CNAME记录、TXT记录、AAAA记录、NS记录
图片滚动(UP)的JS代码详解(offsetTop、scrollTop、offsetHeigh)【转】
关于滚动相关的属性【转】
为什么JSP改动不需要重启服务器
htmlparser 学习
热门文章
httpclient中文API
一些javaer博客
Servlet 单例多线程【转】
学习CGI脚本 (脚本)
maven仓储搭建
asp.net web api下MongoDB使用心得
haartraining
Opencv haar training-特征训练器
C#对称加密(3des)和非对称加密(rsa)算法
IIS调用C++导出函数
Copyright © 2011-2022 走看看