【问题标题】:add image button mouseover event添加图像按钮鼠标悬停事件
【发布时间】:2011-06-18 16:23:18
【问题描述】:

我有网络表单,我将图像(图像按钮)添加到表中,该表是在运行时从数据库中动态创建的...有一个静态图像,它会根据鼠标悬停在动态图像上而改变...

代码如下:

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);

我该怎么做...

谢谢...

【问题讨论】:

    标签: c# image events mouseover imagebutton


    【解决方案1】:

    使用 CSS 伪选择器hover

    为您的图像按钮添加类:

    btnProduct.CssClass = "hoveredButton";
    

    在你的 CSS 中定义 hoverButton 类:

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

    【讨论】:

    • thx 但不完全是我需要的首先我的图像是动态的,我从文件夹中获取它们...
    【解决方案2】:

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

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 2012-12-11
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多