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

发布于 10-15 01:23 字数 1589 浏览 4 评论 0原文

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

这是代码:

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

我该怎么办...

谢谢...

i have web form and i added image(imagebutton) into table which is dynamically created in runtime from database... there is a static image and it will changed according to dynamic image(s) mouse over...

here is the code:

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

how can i do this...

thank you...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看春风乍起2024-10-22 01:23:11

使用CSS伪选择器悬停

将类添加到您的 imagebutton:

btnProduct.CssClass = "hoveredButton";

在 css 中定义 hoverButton 类:

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

Use CSS pseudo selector hover.

Add class to your imagebutton:

btnProduct.CssClass = "hoveredButton";

Define hoverButton class in your css:

hoveredButton:hover{background-image:url('path-to-your-image')}
深爱成瘾2024-10-22 01:23:11

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

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

In case anyone wants the formatted code:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文