开发者

add image button mouseover event

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.I开发者_JAVA技巧mageUrl = @"/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...


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')}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜