---
title: "To bind images in repeater using asp.net"  
description: "To bind images in repeater using asp.net"  
author: "Anonymous User"  
published: 2015-06-01  
updated: 2015-06-01  
canonical: https://www.mindstick.com/forum/23275/to-bind-images-in-repeater-using-asp-dot-net  
category: ".net"  
tags: ["c#", "asp.net"]  
reading_time: 1 minute  

---

# To bind images in repeater using asp.net

in this [sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) i want to bind the [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) from [local](https://www.mindstick.com/forum/546/how-to-create-local-user-in-windows-8) drive to [repeater](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) but not bind properly.\

```
string[] filePaths = Directory.GetFiles("D:\\Users\\Images\\Pictures\\");            List<ListItem> files = new List<ListItem>();            foreach (string filePath in filePaths)            {                string fileName = Path.GetFileName(filePath);                files.Add(new ListItem(fileName, @"D:\Users\Images\Pictures\" + fileName)); //i can get image name  --D:\Users\Images\Pictures\flight.jpg            }            Repeater1.DataSource = files;            Repeater1.DataBind(); <asp:Repeater ID="Repeater1" runat="server">                        <ItemTemplate>                            <li>                                <img src='<%# DataBinder.Eval(Container.DataItem,"Value") %>' title='<%# (DataBinder.Eval(Container.DataItem,"Text").ToString()).Split('.')[0].ToString() %>' alt=""></li>                        </ItemTemplate>                    </asp:Repeater>
```

## Replies

### Reply by Anonymous User

Create a GenericHandler.

Note: When your application moves to production, You need to make sure D:\Users\Images folder exists in web server.

```
public class ImageHandler : IHttpHandler{    public void ProcessRequest(HttpContext context)    {        string fileName = context.Request.QueryString["filename"];        context.Response.ContentType = "image/jpeg";        context.Response.TransmitFile(@"D:\Users\Images\Pictures\" + fileName);    }     public bool IsReusable    {        get { return false; }    }}
```

**ASPX**

```
<asp:Repeater ID="Repeater1" runat="server">    <ItemTemplate>        <asp:Image runat="server"             ImageUrl='<%# "~/ImageHandler.ashx?filename=" + Eval("Value") %>' />    </ItemTemplate></asp:Repeater> protected void Page_Load(object sender, EventArgs e){    if (!IsPostBack)    {        string[] filePaths = Directory.GetFiles(@"D:\Users\Images\Pictures");        List<ListItem> files = new List<ListItem>();        foreach (string filePath in filePaths)        {            string fileName = Path.GetFileName(filePath);            files.Add(new ListItem(fileName, fileName));         }        Repeater1.DataSource = files;        Repeater1.DataBind();    }}
```


---

Original Source: https://www.mindstick.com/forum/23275/to-bind-images-in-repeater-using-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
