Datalist控件中ItemTemplate绑定了隐藏的一个按钮,鼠标移动到ItemTemplate单元中,如何显示出来?
或者
使用层的方式,当鼠标移动到该单元格中,将包含这个按钮的层显示出来?
小弟初接触.NET,求各位大神帮忙,谢谢!!

解决方案 »

  1.   


     <script type="text/javascript">
     function hiden(obj)
     {
        obj.style.display  = "none";
     }
     function show(obj)
     {
        obj.style.display = "";
     }    
    </script>
     <div onmousemove ="hiden(this);"  onmouseout="show(this)">
     <asp:CheckBox ID="CheckBox1" runat="server" onmousemove ="hiden(this);"  onmouseout="show(this)" />
     </div>你可以在不同的控件里写不同的事件调用这两个方法来控制隐藏或者显示
      

  2.   

    zifengshen1981兄弟,谢谢
    但是datalist的模板是从数据库读取数据后自动生成的啊,鼠标移动到单元格怎么显示呢?
      

  3.   

    不管什么控件,最终都生成 HTML代码,自己分析下代码,然后确定鼠标移动事件绑定在每行的哪个控件上,再在该行找到隐藏的控件,用JS实现其显示或隐藏。建议用Repeater控件
      

  4.   

    后台找到你要的控件..Button1 注册属性。。
    Button1.Attributes.Add("onmousemove","hiden(this);")
      

  5.   

    谢谢各位兄弟,比如我有如下datalist,已经绑定,请问鼠标移动到单元格,怎么把ImageButton1给显示出来?
    <asp:DataList ID="datalist1" DataKeyField ="id" runat="server" RepeatColumns="8" RepeatDirection="Horizontal"   Width="889px" >
            <ItemTemplate>
                <table style="width: 95%; height: 193px">  
                    <tr >
                        <td  colspan="3" style="height: 21px">
                            <strong>
                            商品名称:<%#DataBinder.Eval(Container.DataItem, "name")%></strong></td>
                    </tr>
                    
                    <tr>
                        <td colspan="3" style="height: 25px">
                            <table style="width: 95%; height: 46px">
                                <tr>
                                    <td rowspan="3" style="width: 91px; height: 45px" align="center">
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~buy.gif" ToolTip="购买"
                                            Visible="False" Height="22px" Width="25px" /></td>
                                    
                                </tr>
                                
                            </table>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
      

  6.   


    <script type="text/javascript">
            function hiden(obj) {
                document.getElementById(obj).style.display = "none";
                //obj.style.display = "none";
            }
            function show(obj) {
                document.getElementById(obj).style.display = "";
                //obj.style.display = "";
            }
        </script>
    <table style="width: 95%; height: 193px" onmousemove="show('imgdiv')" onmouseout="hiden('imgdiv')">
                    <tr>
                        <td colspan="3" style="height: 21px">商品名称:</td>
                    </tr>
                    <tr>
                        <td colspan="3" style="height: 25px">
                            <table style="width: 95%; height: 46px">
                                <tr>
                                    <td rowspan="3" style="width: 91px; height: 45px" align="center">
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                        <div id="imgdiv" style="display:none">
                                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~buy.gif" ToolTip="购买" 
                                             Height="22px" Width="25px" />
                                        </div>
                                    </td>                            </tr>                        </table>
                        </td>
                    </tr>
                </table>
      

  7.   

    这个还只能对层进行控制,不能对img进行控制,如果一开始设置visable = false 那么这个控件都找不到了 谈何去控制。所以只需要对层进行设置即可
      

  8.   

    可以使用jquery的bind方法,将每一行的mouseover事件绑定到对应单元格,然后再进行控件的显示隐藏操作,不是太难。
      

  9.   

    非常简单,看好了,我只说一次:
    第一种方法:通过Repeater这个控件的ItemDataBound这个事件(其它绑定控件也有类似这个控件),获得对应按钮控件的div,并且显示出来。第二种方法:用jquery的类选择器,给你要显示的按钮div标签加上一定的规律,然后$(".class")获得所有按钮的div层,再移动事件里面写$(".class").attr("style","display:block");就能够显示了。
      

  10.   


    qingfeng_wu熊可能对我说的理解错了,我的并非固定按钮或控件,我是在DataList中的ItemTemplate里面的中增加一个层,这个层当鼠标移动到到该table中,显示层。由于ItemTemplate是个模板,数据绑定后会有许多由该模板生成的单元,当鼠标移动到不同的单元,会显示该单元的层,小弟愚笨,这个还真不好做。
      

  11.   


    qingfeng_wu熊可能对我说的理解错了,我的并非固定按钮或控件,我是在DataList中的ItemTemplate里面的中增加一个层,这个层当鼠标移动到到该table中,显示层。由于ItemTemplate是个模板,数据绑定后会有许多由该模板生成的单元,当鼠标移动到不同的单元,会显示该单元的层,小弟愚笨,这个还真不好做。我知道你要这个效果,我上面不是说了吗:给你要显示的按钮div标签加上一定的规律,规律是自己加的,然后按照自己的需求去写算法。