PDA

Click to See Complete Forum and Search --> : Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.


aftab69
Aug 28th, 2005, 09:20 AM
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:

<%@ 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>

Hack
Aug 29th, 2005, 05:35 AM
Moved from ASP.NET CodeBank.

mendhak
Aug 29th, 2005, 06:47 AM
#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)

aftab69
Aug 30th, 2005, 12:57 AM
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:

<asp:Image height=100 width=100 ImageUrl='<%# 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: email2aftab@gmail.com

mendhak
Aug 30th, 2005, 11:41 AM
Have you explored the ItemDataBound event for setting the ImageUrl instead of doing it in the ASPX?

aftab69
Aug 31st, 2005, 06:31 AM
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

email2aftab@gmail.com
s_aftab79@yahoo.com