Ajax实现DataGrid/DataList动态ToolTip

系统 1943 0

Ajax实现DataGrid/DataList动态ToolTip
1.建立一aspx页面,html代码 2.cs代码

using System.Data.SqlClient;
using System.IO;

protected void Page_Load( object sender,EventArgse)
{
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 " ];
SqlConnectionconn
= new SqlConnection(connStr);
string sql = " select*fromtestimagewhereuserid=' " + ID + " ' " ;
SqlCommandcmd
= new SqlCommand(sql,conn);
conn.Open();
SqlDataReaderdr
= cmd.ExecuteReader();

string s = @" <tablecellspacing='0'cellpadding='4'width='300'height='200'border='0'id='GridView1'style='color:#333333;border-collapse:collapse;'> " ;
if (dr.Read())
{
s
+= " <trstyle='color:#333333;background-color:#FFFBD6;'> " ;
s
+= " <tdwidth='50'>名称:</td> " ;
s
+= " <td> " + dr[ " UserName " ] + " </td> " ;
s
+= " </tr> " ;
s
+= " <trstyle='color:#333333;background-color:White;'> " ;
s
+= " <tdscope='col'>描述:</td> " ;
s
+= " <td> " + dr[ " Description " ] + " </td> " ;
s
+= " </tr> " ;
}

s
+= " </table> " ;
dr.Close();
conn.Close();
this .Response.Write(s);
this .Response.End();
}

#endregion


saveimage #region saveimage
protected void Button2_Click( object sender,EventArgse)
{
StreamImageStream;
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);

SqlConnectionconn
= new SqlConnection(ConfigurationSettings.AppSettings[ " ConnectionString " ]);
SqlCommandcomm
= new SqlCommand( " insertintotestimage(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*fromtestimage " ;
DataSetds
= GetDataSet(sql);
this .DataList1.DataSource = ds;
this .DataList1.DataBind();
}

#endregion


GetDataSet #region GetDataSet
private DataSetGetDataSet( string sql)
{
string constring = System.Configuration.ConfigurationSettings.AppSettings[ " ConnectionString " ];
SqlDataAdaptersda
= new SqlDataAdapter(sql,constring);
DataSetds
= 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 )COLLATEChinese_PRC_CI_AS NULL ,
[ Image ] [ image ] NULL ,
[ Path ] [ nvarchar ] ( 500 )COLLATEChinese_PRC_CI_AS NULL ,
[ Type ] [ nvarchar ] ( 20 )COLLATESQL_Latin1_General_CP1_CI_AS NULL ,
[ Description ] [ nvarchar ] ( 2000 )COLLATEChinese_PRC_CI_AS NULL
)
ON [ PRIMARY ] TEXTIMAGE_ON [ PRIMARY ]
GO
< 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
color: #000000; backgroun
分享到:
评论

Ajax实现DataGrid/DataList动态ToolTip


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论