在 绑定事件里,设置name单元格的onmouseover属性

解决方案 »

  1.   

    热烈祝贺ASP.NET群7947148成立了。
      

  2.   

    你在数据库存的图片是地址还image二进制流?
    private void DataGrid1_ItemDataBound(object sender System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType!=ListItemType.Header&&e.Item.ItemType=ListItemType.Footer)
    {e.Item.Cells[1].Attributes.Add("onmouseover","showpic("+PIC+")");}
    }
    showpic(pic)函数在前台先写好。里面可以是一段鼠标悬停类似Tooltip显示图片的代码。
    还比较麻烦的,自己baidu一下相关代码,有。
      

  3.   

    谢谢楼上的朋友,
    我是存的二进制,
    我去网上找了好久,也没找到点有用的CODE,
    楼上的朋友能不能再给点例子?
    谢谢!!!
      

  4.   

    我简单做了一个,测试成功,也是抄网上的,隐藏一个div,div的背景图是一个类似消息框的图片,当鼠标移到Name字段的时候显示div,移开又隐藏掉,至于绑定数据库的图片,应该你也会了<HTML>   
      <HEAD>   
      <title>WebForm3</title>   
      <meta   content="Microsoft   Visual   Studio   .NET   7.1"   name="GENERATOR">   
      <meta   content="C#"   name="CODE_LANGUAGE">   
      <meta   content="JavaScript"   name="vs_defaultClientScript">   
      <meta   content="http://schemas.microsoft.com/intellisense/ie5";   name="vs_targetSchema">   
      <script>       
      function     show(o){       
      var     m=document.getElementById("m")       
      m.style.pixelLeft=getL(o)       
      m.style.pixelTop=getT(o)+o.offsetHeight       
      m.style.visibility=''       
      }       
          
      function     hide(){       
      document.getElementById("m").style.visibility='hidden'       
      }       
          
      function     getL(e){       
      var     l=e.offsetLeft;       
      while(e=e.offsetParent){       
      l+=e.offsetLeft;       
      }       
      return     l       
      }       
          
      function     getT(e){       
      var     t=e.offsetTop;       
      while(e=e.offsetParent){       
      t+=e.offsetTop;       
      }       
      return     t       
      }       
      </script>   
      </HEAD>   
      <body   ms_positioning="GridLayout">   
      <form   id="products_form"   runat="server">   
      <asp:DataGrid   id="DataGrid1"   style="Z-INDEX:   101;   LEFT:   7px;   POSITION:   absolute;   TOP:   1px"   runat="server"   AutoGenerateColumns="False"   Width="192px"   Height="281px">   
      <Columns>   
      <asp:TemplateColumn   HeaderText="username">   
      <ItemTemplate>   
      <asp:Label   ID="i"   onmouseover="show(this)"   onmouseout="hide()"   Runat=server><%#   DataBinder.Eval(Container.DataItem,"name")   %></asp:Label>   
      <div   id="m"   style="PADDING-RIGHT:20px;PADDING-LEFT:20px;Z-INDEX:100;VISIBILITY:hidden;PADDING-BOTTOM:20px;PADDING-TOP:20px;POSITION:absolute; left: 162px; top: 62px; background-color: transparent; border-top-width: 1px; border-left-width: 1px; border-left-color: black; background-image: url(../Images/MsgBox.gif); border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black; width: 278px; height: 199px;"   onmouseover="show(i)"   onmouseout="hide()">   
      <img   src="../Images/Logo.png">
      </div>   
      </ItemTemplate>   
      </asp:TemplateColumn>   
      </Columns>   
      </asp:DataGrid>   
      </form></body>   
      </HTML>
      

  5.   

    利用AJAX    在每行帮定数据时给每行添加一个onmouseover事件      
    private void DataGrid1_ItemDataBound(object sender System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType!=ListItemType.Header&&e.Item.ItemType=ListItemType.Footer)
    {e.Item.Cells[1].Attributes.Add("onmouseover","showpic("+PIC+")");}
    }
    这个是DATAGRID里给每行帮定数据时添加onmouseover事件的例子、你看着做做看
    然后在客户端写一个函数拿到某行连接的图片URL  这样是可以实现的  无刷新的
      

  6.   

    rowDataBound 里面设置onmouseOver事件