zoukankan
html css js c++ java
DataGrid实现tooltip功能
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
#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
#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
#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
}
查看全文
相关阅读:
THINKPHP 错误:Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
Vs2013 坑爹的Target framework问题
在使用Vs2013打开Vs2008的解决方案时出现了以下错误:此版本的应用程序不支持其项目类型(.csproj)
sql server2008R2 无法连接到WMI提供程序。你没有权限或者该服务器无法访问
SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间。
[UE4]手持多把枪的位置调节
[UE4]函数分组
[UE4]射击起点、终点的计算方法
[UE4]条件融合动画: Blend Posed by int
[UE4]函数和事件的区别
原文地址:https://www.cnblogs.com/Fooo/p/604600.html
最新文章
IDEA设置代码颜色主题(同Sublime Text 3的代码颜色一样)
Windows使用telnet验证服务端口是否通
CentOS 安装抓包工具wireshark-tshark抓包工具
查看CentOS版本信息
Windows安装nginx服务
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(10)-系统菜单栏[附源码]
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(9)-MVC与EasyUI结合增删改查
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(8)-MVC与EasyUI DataGrid 分页
ASP.NET MVC5+EF6+EasyUI 后台管理系统(7)-MVC与EasyUI DataGrid
ASP.NET MVC5+EF6+EasyUI 后台管理系统(6)-Unity 依赖注入
热门文章
ASP.NET MVC5+EF6+EasyUI 后台管理系统(5)-EF增删改查
ASP.NET MVC5+EF6+EasyUI 后台管理系统(4)-创建项目解决方案
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(3)-漂亮系统登陆界面
ASP.NET MVC5+EF6+EasyUI 后台管理系统(2)-easyui构建前端页面框架[附源码]
SQL Server 存储过程生成insert语句
VS web.config/app.conifg配置文件自定义类型使用智能感知功能
ASP.NET MVC 重命名[命名空间]而导致的错误及发现的ASP.NET MVC Bug一枚
解决ThinkPHP的Create方法失效而没有提示错误信息的问题
WordPress 获取指定分类ID的分类信息
THINKPHP 验证码不显示
Copyright © 2011-2022 走看看