简体   繁体   English

ASP.NET C#如何在悬停时放大GridView DataBound imageField图片?

[英]ASP.NET C# How to enlarge GridView DataBound imageField picture when hoverover?

I am doing school work and need some help, I want the image in a 'Relevant Information' ImageField column that is DataBound to be enlarged when hoverover. 我正在做学校工作并需要一些帮助,我希望将图像放在“相关信息”ImageField列中,即在悬停时放大DataBound。 Here are my codes: 这是我的代码:

    <div style="height:200px; width: 610px; overflow: auto;">
                <asp:GridView ID="GV_insView" runat="server"
            AutoGenerateColumns="False"
            CssClass="Grid" AlternatingRowStyle-CssClass="alt" Width="511px">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
            <Columns>
                <asp:BoundField HeaderText="Customer ID" DataField="NRIC" />
                <asp:BoundField HeaderText="Insurance Type" DataField="insType" />
                <asp:BoundField HeaderText="Date Filed" DataField="dateFiled" DataFormatString="{0:dd/MM/yyyy}"/>
            <asp:ImageField HeaderText="Relevant Information" DataImageUrlField="relInfo" ControlStyle-Width="100" ControlStyle-Height="100"> 
              </asp:ImageField>
            </Columns>
        </asp:gridview>
                    </div>

You have to write custom JavaScript Function and CSS to support this. 您必须编写自定义JavaScript函数和CSS来支持此功能。

Please find the example code below for how you can do this. 请在下面找到示例代码,了解如何执行此操作。

<script type="text/javascript">
    $(function () {
        $("[id*=GridView1] td").hover(function () {
            $("td", $(this).closest("tr")).addClass("hover_row");
        },function(){
            $("td", $(this).closest("tr")).removeClass("hover_row");
        });
    });
</script>

and the CSS you will use CSS3 property of transform Scale to enlarge on hover. 和CSS你将使用转换的CSS3属性在悬停时放大。

<style type="text/css">
    body
    {
        font-family: Arial;
        font-size: 10pt;
    }
    td
    {

    }
    .hover_row
    {
        -ms-transform: scale(2, 3); /* IE 9 */
        -webkit-transform: scale(2, 3); /* Safari */
         transform: scale(2, 3);
    }
</style>

For complete solution you can check this link which is the source of the information above. 要获得完整的解决方案,您可以查看此链接,该链接是上述信息的来源。 Change row color on GridView Hover ASP Snippets 在GridView Hover ASP Snippets上更改行颜色

For only one boundfield to have some specific CSS you can try this. 只有一个boundfield有一些特定的CSS你可以试试这个。

<asp:BoundField DataField="Count" HeaderText="Count">
    <ItemStyle CssClass="yourclass"></ItemStyle>
</asp:BoundField>

This way, all boundfields of Image will get that CSS class of hover. 这样,Image的所有boundfield都将获得悬停的CSS类。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM