[英]How can I add image into Gridview Databound dynamically using ASP.NET C#
我需要在運行時在特定單元格中向 gridview 數據綁定添加圖像圖標。
我已經開始編寫代碼,但我不確定如何完成它,因為使用此代碼圖像不會在 gridview 中顯示...
見下文:
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.DataItem != null)
{
ImageButton image = new ImageButton();
image.ImageUrl = "C:/inetpub/wwwroot/img/add-page-red.gif";
e.Row.Cells[2].Controls.Add(image);
}
}
任何幫助將不勝感激......謝謝。
// In .aspx page use below code-
//for imageUrl you have to call the method which is defined in code behind-
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Image ID="img" runat="server" ImageUrl='<%# GetImage() %>'/>
</ItemTemplate>
</asp:TemplateField>
// In code behind return the image path-
public static string GetImage()
{
return "../Images/Image.jpg";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.