2011-01-31 62 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); 
相關問題