Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
Hi there! I am new to ASP.Net I am not able to display images in the Data Repeater control. It does display text but not the images. I have created a Folder named Images in the root directory and has all the images there. And the path of these images are in the database table named Employee and column name PicturePath. But the images still doesn't show, only the data(i.e the text).
The line of code that I've used for displaying pictures is:
<asp:Image height=100 width=100 Img scr='<%# Container.DataItem("PicturePath")%>' runat="server" ID = "Images"/>
Here, PicturePath is the column where the Path of the picture is stored.
The complete code is shown below:
VB Code:
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<HEAD>
<!— Chapter3/Repeater1.aspx —>
<script language="VB" runat="server" Debug="true">
Sub Page_Load(src As Object, e As EventArgs)
If Not IsPostBack
bindListControl
End If
End Sub
Sub bindListControl()
Dim myConn As OleDbConnection
Dim myOleDbAdapter As OleDbDataAdapter
Dim connStr, sqlStr As String
Dim myDataSet As New Dataset
connStr="Provider=Microsoft.Jet.OLEDB.4.0;" _
+ "Data Source=C:\Inetpub\wwwroot\WebApplication1\test.mdb"
sqlStr = "SELECT EmpID, Name, Tel, Address, PicturePath FROM Employee"
myConn= New OleDbConnection(connStr)
myConn.Open()
myOleDbAdapter =New OleDbDataAdapter(sqlStr,myConn)
myOleDbAdapter.Fill(myDataSet,"dtProducts")
repeater1.DataSource=myDataSet.Tables("dtProducts")
repeater1.DataBind()
End Sub
</script>
</HEAD>
<body>
<h2>Data Repeater Control</h2>
<asp:repeater id="repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Image height=100 width=100 Img scr='<%# Container.DataItem("PicturePath")%>' runat="server" ID = "Images"/>
</td>
</tr>
<td>
Emp ID: <i><b>
<%# Container.DataItem("EmpID")%>
</b></i>
<br>
Name: <i><b>
<%# Container.DataItem("Name")%>
</b></i>
<br>
Phone: <i><b>
<%# Container.DataItem("Tel")%>
</b></i></b>
<br>
Address: <i><b>
<%# Container.DataItem("Address")%>
</b></i></b>
<br>
<br>
<br>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate>
</table>
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
</body>
</HTML>
Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
Moved from ASP.NET CodeBank.
Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
#1: There is no "Scr" attribute of the image tag.
#2: It should either be Src or ImageUrl. (I don't have the IDE open right now but I'm pretty sure it's one of these two)
Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
Hi there!
Thanks for your reply. I have tried both the options that you told me. i.e. scr and imageUrl. But it doesn't seem to work. The repeater control displays data but not the images. The code for it is:
VB Code:
<asp:Image height=100 width=100 [B]ImageUrl[/B]='<%# Container.DataItem("PicturePath")%>' runat="server" ID = "Images"/>
Maybe... is there any other thing that I need to do. Please help.
Thank you so very much in this regard.
-Aftab-
My ID: [email protected]
Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
Have you explored the ItemDataBound event for setting the ImageUrl instead of doing it in the ASPX?
Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.
Hi there!
Thanks for your reply dear. I was just trying to figure out how I can do it. Do you have any sample project or application in which you have used the Data Repeater Control. Maybe I can refer to that and it can help me solve my query.
Thanks once again for your kind help.!
Your truly,
Aftab
[email protected]
[email protected]