2011-01-31 65 views
0

我有网页形式,我添加图像(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); 

我怎么能做到这一点...

谢谢...

回答

0

使用CSS伪选择hover

添加类到您的ImageButton:

btnProduct.CssClass = "hoveredButton"; 

定义hoverButton类在你的CSS:

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

THX但不正是我需要首先我的图像动态即时通讯从文件夹中获取... – 2011-02-01 07:30:04

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); 
相关问题