[英]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.