Adding images to a grid view server control programmatically

160 views
Skip to first unread message

Kalyani

unread,
Aug 15, 2008, 9:54:46 AM8/15/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Is there a way to add images to a grid view server control
programmatically ? I tried storing the image url in the database but
only the url string gets displayed instead of the actual image.
Can anyone please suggest.
Message has been deleted

wagner reatto

unread,
Aug 16, 2008, 8:45:21 AM8/16/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
vb samples

-=-=-=-=-=-
.aspx
-=-=-=-=-=-

<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

</div>

-=-=-=-=-=-
.vb
-=-=-=-=-=-

Private AnyDataSourceArray() As String = {"sample"} ' any datasource!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
GridView1.DataSource = AnyDataSourceArray ' bind ur datasource
GridView1.DataBind()
End If
End Sub

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
CType(e.Row.FindControl("Image1"), Image).ImageUrl = "loading.gif"
' load your url image. may be a table column value
End If
End Sub

Cerebrus

unread,
Aug 17, 2008, 3:46:12 AM8/17/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Isn't it obvious ? The Image url retrieved from the db must be bound
to the ImageUrl property of an Image control for it to be displayed as
an image.
Reply all
Reply to author
Forward
0 new messages