Ajax实现DataGrid/DataList动态ToolTip


1.建立一aspx页面,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

    
GetDescriptionByID

    
save image

    
BindData

    
GetDataSet
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

 

 

http://www.cnblogs.com/singlepine/archive/2006/05/14/399520.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")%>);" οnmοuseοut="kill();" src='<%# DataBinder.Eval(Container.DataItem, "Path"%>' height='150'/>
         
</ItemTemplate>
      
</asp:DataList>    
    
</div>
    
</Form>
 
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值