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

C# 添加图像按钮鼠标悬停事件,c#,image,events,mouseover,imagebutton,C#,Image,Events,Mouseover,Imagebutton,我有一个web表单,我将图像(imagebutton)添加到表中,该表是在运行时从数据库动态创建的。。。有一个静态图像,它将改变根据动态图像(s)鼠标在 代码如下: HtmlTable tbProductImage = new HtmlTable(); HtmlTableRow trImageRow = new HtmlTableRow(); for (int j = 0; j < columnCount; j

我有一个web表单,我将图像(imagebutton)添加到表中,该表是在运行时从数据库动态创建的。。。有一个静态图像,它将改变根据动态图像(s)鼠标在

代码如下:

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);
HtmlTable tbProductImage=new HtmlTable();
HtmlTableRow trImageRow=新的HtmlTableRow();
对于(int j=0;j
我怎样才能做到这一点

谢谢…

使用CSS伪选择器

将类添加到imagebutton:

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);
HtmlTable tbProductImage=new HtmlTable();
HtmlTableRow trImageRow=新的HtmlTableRow();
对于(int j=0;j
thx,但不完全是我需要的。首先,我的图像是动态的,我从文件夹中获取它们。。。