在datagrid中有一列是图片,有没有办法让鼠标移动到图片上时让原来的图片改换成另外一张图片,也就是说在itemdatabound中给那列加个onmouseover事件,可是我这样做了总不能成功,请大家帮我看看有没有好的办法,谢谢。

解决方案 »

  1.   

    可以.e.Item.Cells[2].Attributes.Add("onmouseover","this.firstChild.src='b.jpg'");
    e.Item.Cells[2].Attributes.Add("onmouseout","this.firstChild.src='a.jpg'");
      

  2.   

    在模板列中写.<a href='bb.asp'><img src="<%#DataBinder.Eval(Container.DataItem,"url")%>" ></a>
      

  3.   

    此时脚本要改一下.this.firstChild==>
    this.firstChild.firstChild
      

  4.   

    在图片外加一个<a runat="server" id="aa">你的图片</a>
    给aa的href值,应该可以的吧,或用图片链接控件个人见解,共同学习
      

  5.   

    <asp:TemplateColumn HeaderText="View"> <ItemTemplate>
    </ItemTemplate>
    </asp:TemplateColumn>
    模版列像上面那样写的,可以e.Item.Cells[6].Attributes.Add("onmouseover","this.style.background='Black'");
    e.Item.Cells[6].Attributes.Add("onmouseout","this.style.background='Red'");
    来改变背景色,可是没法e.Item.Cells[6].Attributes.Add("onmouseover","this.firstChild.src='view_on.jpg'");
    e.Item.Cells[6].Attributes.Add("onmouseout","this.firstChild.src='view.jpg'");
    这样改变图片,如果给模版列加<a href='strUrl'><img src="<%#strImg%>" ></a>又不知道怎么改变图片和连接地址,因为连接地址是不一样,而且要在鼠标放上去和移开的时候显示不同的图片,不知道怎么做了,请大家帮忙看看,谢谢。
      

  6.   

    function change( obj )
    {
    obj.background = "view_on.gif";
    }
    e.Item.Cells[6].Attributes.Add("onmouseover","change( this )");
    可以在aspx页面中检测到传过来的obj是一个htmltablecell,可是obj.background = "view_on.gif";赋值为什么不起作用呢,谢谢
      

  7.   

    <asp:TemplateColumn HeaderText="View"> <ItemTemplate>
    </ItemTemplate>
    </asp:TemplateColumn>
    模版列像上面那样写的
    =======
    里面怎么没有图片?
      

  8.   

    如果原来是空的话应该这样写
    Add("onmouseover","this.innerHTML='<img src=\'aa.jpg\'>'");
      

  9.   

    你要写在ItemCreate事件
    或者ItemDataBand事件中。。楼上的几位的方法肯定可以实现你的要求
      

  10.   

    Click the link to solve your problem.Good luck!