Bind Images from Folder to Repeater to Create Image Album in Asp.Net C# VB.Net

To create Image Album the Asp.Net Repeater control is one of the best choice. In several project I found lot of examples using the Asp.Net Repeater Control. Here in this example I will explain “How we can create an Image album using Asp.Net Repeater Control“.

Related Article:
Bind Images from Folder to DataList to Create Image Album in Asp.Net C# VB.Net

Bind Images from Folder to Repeater to Create Image Album in Asp.Net Csharp VB.Net

Repeater Control to Bind Images from Folder:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Repeater ID="Repeater1" runat="server">
            <div style="display:inline;">
                <img style='border:1px solid #000000' alt="Bind Images from Folder Asp.Net Repeater Control" src="<%# Container.DataItem %>" width="200px" height="200px"/>

Note: Using display:inline to display images Horizontally.

Server Side Code to Bind Images from Folder into Repeater:
C# Code:

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            string[] filePaths = Directory.GetFiles(Server.MapPath("Images/"));
            Repeater1.DataSource = filePaths;

Note: Don’t forget to add “System.IO”.

VB.Net Code:

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim filePaths As String() = Directory.GetFiles(Server.MapPath("Images/"))
            Repeater1.DataSource = filePaths
        End If
    End Sub

Download Code Example C#        Download Code Example VB.Net

Posted in .Net,, C#, Repeater, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *