繁体   English   中英

添加图像按钮鼠标悬停事件

[英]add image button mouseover event

我有Web表单,并且将image(imagebutton)添加到了在运行时从数据库中动态创建的表中....有一个静态图像,它将根据动态图像在鼠标上方的变化而变化...

这是代码:

HtmlTable tbProductImage = new HtmlTable();
                    HtmlTableRow trImageRow = new HtmlTableRow();
                    for (int j = 0; j < columnCount; j++) {
                        if (filteredFileList.Count != 0) {
                            HtmlTableCell tdImageRow = new HtmlTableCell();
                            Panel panel = new Panel();
                            ImageButton btnProduct = new ImageButton();                           
                            btnProduct.ID = "btn" + filteredFileList[j].Name.Substring(0, filteredFileList[j].Name.LastIndexOf("."));
                            btnProduct.ImageUrl = @"/ysyp/Images/Products/" + filteredFileList[j].Name; 
                            btnProduct.Width = 50;
                            btnProduct.CommandName = "Click";
                            Page.ClientScript.GetPostBackEventReference(btnProduct, "btnProduct_Click");
                            btnProduct.CommandArgument = filteredFileList[j].Name;
                            btnProduct.Click += new ImageClickEventHandler(btnProduct_Click);
                            panel.Controls.Add(btnProduct);
                            trImageRow.Cells.Add(tdImageRow);
                            tdImageRow.Controls.Add(panel);
                        }
                    }
                    tbProductImage.Rows.Add(trImageRow);
                    tdProduct.Controls.Add(tbProductImage);

我怎样才能做到这一点...

谢谢...

使用CSS伪选择器悬停

将类添加到您的图像按钮:

btnProduct.CssClass = "hoveredButton";

在CSS中定义hoverButton类:

hoveredButton:hover{background-image:url('path-to-your-image')}

如果有人想要格式化的代码:

HtmlTable tbProductImage = new HtmlTable();
HtmlTableRow trImageRow = new HtmlTableRow();
for (int j = 0; j < columnCount; j++)
{
    if (filteredFileList.Count != 0)
    {
        HtmlTableCell tdImageRow = new HtmlTableCell();
        Panel panel = new Panel();
        ImageButton btnProduct = new ImageButton();

        btnProduct.ID = "btn" + filteredFileList[j].Name.Substring(0, filteredFileList[j].Name.LastIndexOf("."));
        btnProduct.ImageUrl = @"/ysyp/Images/Products/" + filteredFileList[j].Name;
        btnProduct.Width = 50;
        btnProduct.CommandName = "Click";

        Page.ClientScript.GetPostBackEventReference(btnProduct, "btnProduct_Click");

        btnProduct.CommandArgument = filteredFileList[j].Name;
        btnProduct.Click += new ImageClickEventHandler(btnProduct_Click);

        panel.Controls.Add(btnProduct);

        trImageRow.Cells.Add(tdImageRow);
        tdImageRow.Controls.Add(panel);
    }
}

tbProductImage.Rows.Add(trImageRow);
tdProduct.Controls.Add(tbProductImage);

暂无
暂无

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

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