2011-12-07 25 views
2

我正在創建一個自定義Gridview控件,根據要求我必須在頂部尋呼機中放置兩個圖像按鈕。在那裏我能夠顯示圖像按鈕,但只有一個圖像imagebutton顯示圖像另一個圖像按鈕沒有。在asp.net中嵌入圖像自定義控件

這裏是代碼:

protected override void InitializePager(GridViewRow row,int columnSpan,PagedDataSource pagedDataSource) 
     { 
//adding refresh button in TopPager 
      ImageButton Refresh = new ImageButton(); 
      Refresh.ToolTip = "Refresh GridView"; 
      Refresh.ImageAlign = ImageAlign.Right; 
      Refresh.AlternateText = "Refresh GridView"; 
      ClientScriptManager cs1 = this.Page.ClientScript; 
      Refresh.ImageUrl = cs1.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.Refresh.gif"); 

// adding button in TopPager to add new record.. 
      ImageButton ExportToPDF = new ImageButton(); 
      ExportToPDF.ToolTip = "Export To PDF"; 
      ExportToPDF.AlternateText = "PDF Export"; 
      ClientScriptManager cs2 = this.Page.ClientScript; 
      ExportToPDF.ImageUrl = cs2.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.PDF.gif"); 
} 

我在assembly.info

[assembly: WebResource("myCustomGrid.Refresh.gif", "image/gif")] 
[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")] 

我錯在那裏設置的屬性生成操作兩個圖像嵌入資源

!任何幫助深表感謝。

回答

0

可能是一個錯字。

您的意思是: -

[assembly: WebResource("myCustomGrid.PDF.gif", "image/gif")] 

,而不是...

[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")] 
+0

是你指出的圖像沒有顯示在imagebutton上。 – masif

+0

兩者看起來都一樣。 – masif

1

是否放置在項目的根這個圖片嗎?因爲,如果不是,你必須添加相對路徑。我不認爲從asssembly路徑。 你必須做出這樣的:

[assembly: WebResource("{Your assembly full name}.{Path to image inside assembly and with replacement '/' to '.'}.{Image name}", "image/gif")] 

例如:

[assembly: WebResource("MyBestProject.Controls.resources.images.myCustomGird.PDF.gif", "image/gif")] 
+0

有兩個圖像'Refresh.gif'和'PDF.gif'在根文件夾中,refresh.gif圖像顯示正常但PDF.gif不是。 – masif

+0

跟着[link]( http://support.microsoft.com/kb/910442) – masif

+0

再次檢查圖像的路徑和屬性構建動作 – Baidaly

0

更新: 當imagebuttons渲染由Refresh.gif和PDF.gif imagebuttons respectively.The PDF.gif生成的HTML不加載,而不是我得到指定的備用文本是在這行代碼ExportToPDF.AlternateText = "PDF Export";

<input align="right" type="image" style="height:20px;width:20px;" alt="Refresh GridView" src="/WebResource.axd?d=CIOcfTt92OMP_aqepr-cGa2E4E8-uaiywsae5-4NcYocrJ-NE-cIL4Qb2JfX3tY0cIa8EwDzWnyeBqNiST34SNpBNuGjVC113XqMTprBN-XU9J7ilPsI6bsaXwHa-Qt30&amp;t=634589418951556073" title="Refresh GridView" name="ctl00$MainContent$customGrid0$ctl01$ctl02"> 



<input type="image" style="height:20px;width:20px;margin-left:480px;" alt="PDF Export" src="/WebResource.axd?d=su3rsVMzKa7BNi4A-JZVUHPhHh3sS-oWW9bmAeK4I0h1A11NHqBD2setFyA3yundDC34YO0gbBoz5G0PHS0uxeQYI66QON_syQhIdlIKs4JzJW6H_oLErMjOZE6Q_slB0&amp;t=634589418951556073" title="Export To PDF" name="ctl00$MainContent$customGrid0$ctl01$ctl01"> 
0

「僅」 2年後,我有一個SI類似問題。我只是通過查看這篇文章和我的問題之間的相似之處來解決我的一個簡單的想法。也許別人會發現這個解決方案在未來有用。

問題出現在名稱的ALLCAPS部分。出於某種原因,UpperLower的名字工作得很好,所有的更低。但我猜測ALLCAPS段在內部轉換爲其他內容,並且不起作用。在我的情況下,將我的圖標從「ARROWLEFT.GIF」重命名爲「ArrowLeft.gif」(文件名,註冊以及對資源的任何引用)修復了此問題。

附加說明:我在同一個項目中創建了另一個圖像,名爲「icon_Calendar.GIF」,在我將其重命名爲「icon_Calendar.gif」之前,該圖像也無法正常工作。