Results 1 to 6 of 6

Thread: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    53

    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:
    1. <%@ Import Namespace="System.Data.OleDb" %>
    2. <%@ Import Namespace="System.Data" %>
    3. <HTML>
    4.     <HEAD>
    5.         <!— Chapter3/Repeater1.aspx —>
    6.         <script language="VB" runat="server" Debug="true">
    7. Sub Page_Load(src As Object, e As EventArgs)
    8.     If Not IsPostBack
    9.         bindListControl
    10.     End If
    11. End Sub
    12.  
    13. Sub bindListControl()
    14.     Dim myConn As OleDbConnection
    15.     Dim myOleDbAdapter As OleDbDataAdapter
    16.     Dim connStr, sqlStr As String
    17.     Dim myDataSet As New Dataset
    18.     connStr="Provider=Microsoft.Jet.OLEDB.4.0;" _
    19.     + "Data Source=C:\Inetpub\wwwroot\WebApplication1\test.mdb"
    20.     sqlStr = "SELECT EmpID, Name, Tel, Address, PicturePath FROM Employee"
    21.     myConn= New OleDbConnection(connStr)
    22.     myConn.Open()
    23.     myOleDbAdapter =New OleDbDataAdapter(sqlStr,myConn)
    24.     myOleDbAdapter.Fill(myDataSet,"dtProducts")
    25.     repeater1.DataSource=myDataSet.Tables("dtProducts")
    26.     repeater1.DataBind()
    27. End Sub
    28.         </script>
    29.     </HEAD>
    30.     <body>
    31.         <h2>Data Repeater Control</h2>
    32.         <asp:repeater id="repeater1" runat="server">
    33.             <ItemTemplate>
    34.                 <table>
    35.                     <tr>
    36.                         <td>
    37.                             <asp:Image height=100 width=100 Img scr='<%# Container.DataItem("PicturePath")%>' runat="server" ID = "Images"/>
    38.                            
    39.                            
    40.                         </td>
    41.                     </tr>
    42.                     <td>
    43.                         Emp ID: <i><b>
    44.                                 <%# Container.DataItem("EmpID")%>
    45.                             </b></i>
    46.                         <br>
    47.                         Name: <i><b>
    48.                                 <%# Container.DataItem("Name")%>
    49.                             </b></i>
    50.                         <br>
    51.                         Phone: <i><b>
    52.                                 <%# Container.DataItem("Tel")%>
    53.                             </b></i></b>
    54.                         <br>
    55.                         Address: <i><b>
    56.                                 <%# Container.DataItem("Address")%>
    57.                             </b></i></b>
    58.                         <br>
    59.                         <br>
    60.                         <br>
    61.                     </td>
    62.                 </tr>
    63.             </ItemTemplate>
    64.             <HeaderTemplate>
    65.                 </table>
    66.             </HeaderTemplate>
    67.             <FooterTemplate>
    68.                 </table>
    69.             </FooterTemplate>
    70.         </asp:repeater>
    71.     </body>
    72. </HTML>

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Unable to display Image in the Data Repeater Control in ASP.Net Plzzz help.

    Moved from ASP.NET CodeBank.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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)

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    53

    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:
    1. <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]

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    53

    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width