Check this sample code. compare with yours and correct if necessary.My images are stored in
img folder of my site My table tblpics contains 2 fields: username and ImageName. In imagename field image paths are stored as
img/id001.jpg. img/id002.jpg and so on..
Sub fillGV()
Dim strDatabaseNameAndLocation As String
strDatabaseNameAndLocation = Server.MapPath("~/App_Data/basic.mdb")
Dim strSQLCommand As String
strSQLCommand = "SELECT * FROM tblpics"
Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
objOleDbDataReader = objOleDbCommand.ExecuteReader()
gdvproducts.DataSource = objOleDbDataReader
gdvproducts.DataBind()
objOleDbConnection.Close()
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
fillGV()
End Sub
Kindly mark this post as "Answer", if it helped you.
basheerkal
Star
10672 Points
2426 Posts
Re: Images in datagrid
Apr 29, 2012 05:36 AM|LINK
Check this sample code. compare with yours and correct if necessary.My images are stored in img folder of my site My table tblpics contains 2 fields: username and ImageName. In imagename field image paths are stored as img/id001.jpg. img/id002.jpg and so on..
See my GridView:
<asp:GridView ID="gdvproducts" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="username" HeaderText="UserName" SortExpression="username" /> <asp:TemplateField HeaderText="Image"> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("ImageName") %>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>My Vb.net Code:
Sub fillGV() Dim strDatabaseNameAndLocation As String strDatabaseNameAndLocation = Server.MapPath("~/App_Data/basic.mdb") Dim strSQLCommand As String strSQLCommand = "SELECT * FROM tblpics" Dim objOleDbConnection As System.Data.OleDb.OleDbConnection objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation) objOleDbConnection.Open() Dim objOleDbCommand As System.Data.OleDb.OleDbCommand objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection) Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader objOleDbDataReader = objOleDbCommand.ExecuteReader() gdvproducts.DataSource = objOleDbDataReader gdvproducts.DataBind() objOleDbConnection.Close() End Sub Protected Sub Page_Load(sender As Object, e As System.EventArgs) fillGV() End Sub(Talk less..Work more)