zoukankan
html css js c++ java
Ajax实现DataGrid/DataList动态ToolTip (转自 小山)
1.建立一aspx页面,html代码
<
html
>
<
head
>
<
title
>
WebForm1
</
title
>
<
style
type
="text/css"
>
.logo
{
}
{
POSITION
:
absolute
}
.dek
{
}
{
Z-INDEX
:
200
;
VISIBILITY
:
hidden
;
POSITION
:
absolute
}
</
style
>
</
head
>
<
body
>
<
Form
runat
="server"
>
<
DIV
class
="dek"
id
="dek"
></
DIV
>
<
script
language
="javascript"
>
Xoffset
=-
20
;
Yoffset
=
20
;
var
nav,yyy
=-
1000
;
var
skn
=
dek.style;
document.onmousemove
=
get_mouse;
//
ajax
var
xmlHttp;
function
createXMLHttpRequest()
{
if
(window.ActiveXObject)
{
xmlHttp
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
else
if
(window.XMLHttpRequest)
{
xmlHttp
=
new
XMLHttpRequest();
}
}
function
startRequest(id)
{
createXMLHttpRequest();
xmlHttp.onreadystatechange
=
handleStateChange;
xmlHttp.open(
"
GET
"
,
"
?ID=
"
+
id,
true
);
xmlHttp.send(
null
);
}
var
content;
function
handleStateChange()
{
if
(xmlHttp.readyState
==
4
)
{
if
(xmlHttp.status
==
200
)
{
content
=
xmlHttp.responseText;
}
}
}
//
tooltip
function
popup(id)
{
startRequest(id);
yyy
=
Yoffset;
document.all(
"
dek
"
).innerHTML
=
content;
skn.visibility
=
"
visible
"
}
function
get_mouse(e)
{
var
x
=
event.x
+
document.body.scrollLeft;
skn.left
=
x
+
Xoffset;
var
y
=
event.y
+
document.body.scrollTop;
skn.top
=
y
+
yyy;
}
function
kill()
{
yyy
=-
1000
;
skn.visibility
=
"
hidden
"
;
}
</
script
>
<
div
>
<
asp:FileUpload
ID
="FileUpload1"
runat
="server"
/><
br
>
名称:
<
asp:TextBox
ID
="txtUserName"
runat
="server"
></
asp:TextBox
><
br
>
描述:
<
asp:TextBox
ID
="TextBox1"
runat
="server"
></
asp:TextBox
><
br
>
<
asp:Button
ID
="Button2"
runat
="server"
OnClick
="Button2_Click"
Text
="保存"
/>
<
asp:DataList
id
="DataList1"
BorderColor
="black"
CellPadding
="1"
CellSpacing
="4"
HorizontalAlign
="Center"
RepeatColumns
="4"
RepeatLayout
="Table"
runat
="server"
ShowFooter
="true"
ShowHeader
="true"
width
="100%"
>
<
ItemTemplate
>
<%
# DataBinder.Eval(Container.DataItem,
"
UserName
"
)
%>
<
br
>
<
img
ID
="img1"
onmouseover
="popup(<%# DataBinder.Eval(Container.DataItem, "
UserID")%
>
);" onmouseout="kill();" src='
<%
# DataBinder.Eval(Container.DataItem,
"
Path
"
)
%>
' height='150'/>
</
ItemTemplate
>
</
asp:DataList
>
</
div
>
</
Form
>
</
body
>
</
html
>
2.cs代码
using
System.Data.SqlClient;
using
System.IO;
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
Page.IsPostBack)
{
BindData();
}
if
(ID
!=
""
)
{
GetDescriptionByID(ID);
}
}
property
#region
property
private
string
ID
{
get
{
if
(Request[
"
ID
"
]
!=
null
&&
Request[
"
ID
"
].ToString()
!=
""
)
{
return
Request[
"
ID
"
];
}
else
{
return
""
;
}
}
}
#endregion
GetDescriptionByID
#region
GetDescriptionByID
private
void
GetDescriptionByID(
string
ID)
{
string
connStr
=
ConfigurationSettings.AppSettings[
"
ConnectionString
"
];
SqlConnection conn
=
new
SqlConnection(connStr);
string
sql
=
"
select * from testimage where userid='
"
+
ID
+
"
'
"
;
SqlCommand cmd
=
new
SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr
=
cmd.ExecuteReader();
string
s
=
@"
<table cellspacing='0' cellpadding='4' width='300' height='200' border='0' id='GridView1' style='color:#333333;border-collapse:collapse;'>
"
;
if
(dr.Read())
{
s
+=
"
<tr style='color:#333333;background-color:#FFFBD6;'>
"
;
s
+=
"
<td width='50'>名称:</td>
"
;
s
+=
"
<td>
"
+
dr[
"
UserName
"
]
+
"
</td>
"
;
s
+=
"
</tr>
"
;
s
+=
"
<tr style='color:#333333;background-color:White;'>
"
;
s
+=
"
<td scope='col'>描述:</td>
"
;
s
+=
"
<td>
"
+
dr[
"
Description
"
]
+
"
</td>
"
;
s
+=
"
</tr>
"
;
}
s
+=
"
</table>
"
;
dr.Close();
conn.Close();
this
.Response.Write(s);
this
.Response.End();
}
#endregion
save image
#region
save image
protected
void
Button2_Click(
object
sender, EventArgs e)
{
Stream ImageStream;
string
Path
=
FileUpload1.PostedFile.FileName;
//
文件名称
int
Size
=
FileUpload1.PostedFile.ContentLength;
//
文件大小
string
Type
=
FileUpload1.PostedFile.ContentType;
//
文件类型
ImageStream
=
FileUpload1.PostedFile.InputStream;
byte
[] Content
=
new
byte
[Size];
int
Status
=
ImageStream.Read(Content,
0
, Size);
SqlConnection conn
=
new
SqlConnection(ConfigurationSettings.AppSettings[
"
ConnectionString
"
]);
SqlCommand comm
=
new
SqlCommand(
"
insert into testimage (UserName,Image,Path,Type,Description) values(@UserName,@Image,@Path,@Type,@Description)
"
, conn);
comm.CommandType
=
CommandType.Text;
comm.Parameters.Add(
"
@UserName
"
, SqlDbType.VarChar,
255
).Value
=
txtUserName.Text;
comm.Parameters.Add(
"
@Image
"
, SqlDbType.Image).Value
=
Content;
comm.Parameters.Add(
"
@Path
"
, SqlDbType.VarChar,
255
).Value
=
Path;
comm.Parameters.Add(
"
@Type
"
, SqlDbType.VarChar,
255
).Value
=
Type;
comm.Parameters.Add(
"
@Description
"
, SqlDbType.VarChar,
2000
).Value
=
this
.TextBox1.Text;
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
#endregion
BindData
#region
BindData
private
void
BindData()
{
string
sql
=
"
select * from testimage
"
;
DataSet ds
=
GetDataSet(sql);
this
.DataList1.DataSource
=
ds;
this
.DataList1.DataBind();
}
#endregion
GetDataSet
#region
GetDataSet
private
DataSet GetDataSet(
string
sql)
{
string
constring
=
System.Configuration.ConfigurationSettings.AppSettings[
"
ConnectionString
"
];
SqlDataAdapter sda
=
new
SqlDataAdapter(sql, constring);
DataSet ds
=
new
DataSet();
sda.Fill(ds);
return
ds;
}
#endregion
3.数据库脚本
if
exists
(
select
*
from
dbo.sysobjects
where
id
=
object_id
(N
'
[dbo].[TestImage]
'
)
and
OBJECTPROPERTY
(id, N
'
IsUserTable
'
)
=
1
)
drop
table
[
dbo
]
.
[
TestImage
]
GO
CREATE
TABLE
[
dbo
]
.
[
TestImage
]
(
[
UserID
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
UserName
]
[
nvarchar
]
(
500
) COLLATE Chinese_PRC_CI_AS
NULL
,
[
Image
]
[
image
]
NULL
,
[
Path
]
[
nvarchar
]
(
500
) COLLATE Chinese_PRC_CI_AS
NULL
,
[
Type
]
[
nvarchar
]
(
20
) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
,
[
Description
]
[
nvarchar
]
(
2000
) COLLATE Chinese_PRC_CI_AS
NULL
)
ON
[
PRIMARY
]
TEXTIMAGE_ON
[
PRIMARY
]
GO
查看全文
相关阅读:
React生命周期函数
云效创建项目应用以及流水线的说明文档
前端工作规范
阮一峰 前端系列教程
js对时间戳的处理 获取时间,昨天,今天,明天,时间不同格式
当天时间小案例--时间戳,获取年月日星期时分秒
React中构造函数constractor,为什么要用super(props)
Java8新特性——Optional类的使用(有效的避免空指针异常)
Java8新特性——新一套时间API的使用
Java8新特性——StreamAPI 的使用
原文地址:https://www.cnblogs.com/Godblessyou/p/1012909.html
最新文章
Net core学习系列(二)——Net Core项目文件简介
Net core学习系列(一)——Net Core介绍
.NET数据挖掘与机器学习开源框架
Redis采坑(一)——数据无法插入,内存溢出
NoSql数据库Redis系列(6)——Redis数据过期策略详解
NoSql数据库Redis系列(5)——Redis主从复制
SpringMVC ajax技术无刷新文件上传下载删除示例
CentOS(Linux)
CentOS(Linux)
git使用笔记(三)(图文说明) 图解提交更改内容的不同方式,涉及代码
热门文章
(转)函数中使用 ajax 异步 同步 返回值错误 主函数显示返回值总是undefined -- ajax使用总结
CentOS7.1 使用资源搜集
SpringMVC项目中中文字符乱码问题及解决办法总结(非专业最优解决办法) -- ajax传值乱码; request.getParameter()乱码;
hibernate像MySQL数据库里面存值是中文乱码的解决合辑
用jquery向网页添加背景图片 拉伸 模糊 遮罩层 代码
背景图片自适应分辨率浏览器大小自动拉伸全屏代码
在Eclipse中查看JDK类库的源代码
eclipse自动补全的设置
React结合AntD的upload组件写头像上传
React中用EChart写面积图
Copyright © 2011-2022 走看看