To bind images in repeater using asp.net

user4416997

In the below code i have a repeater and i want to bind the images from local drive to repeater.But the image is not binding but i can get the image name from the local drive pls help me to solve the issue.

  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>
Win

Client cannot download a file outside of web application's folder. You have two options -

Option 1

Keep images inside a folder of the web application. For example,

enter image description here

Option 2

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();
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NavigateUrl on Repeater ASP.net

From Dev

How to render two column layout using an asp.net repeater

From Dev

How can I bind the single LINQ object to ASP.NET Repeater Control

From Dev

ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

From Dev

ASP.NET Repeater - Eval() for bool?

From Dev

Using foreach with ASP.NET view engine inside a ASP: Repeater is not working

From Dev

repeater item command in asp.net

From Dev

How to dynamically bind asp.net repeater control to datasource

From Dev

asp.net repeater use template in javascript

From Dev

to disable a label of repeater on some condition in asp .net

From Dev

Using Bootstrap tabs with ASP NET repeater

From Dev

asp.net repeater for each row

From Dev

ASP.Net repeater control - using conditional statements

From Dev

asp.net repeater merge columns dynamically

From Dev

How To Make Slideshow Using ASP.NET Repeater

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

Fix header row in repeater in ASP.NET

From Dev

NavigateUrl on Repeater ASP.net

From Dev

Changing the last datarow from a asp:repeater table if data is shown in asp:label using vb.net

From Dev

ASP.NET Converting repeater item to the textbox

From Dev

How to dynamically bind asp.net repeater control to datasource

From Dev

Repeater asp.net tag not working

From Dev

asp.net repeater merge columns dynamically

From Dev

Change the Image size before bind inside Repeater using c# asp.net.

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

Conditional statement for Repeater Controll in ASP.NET

From Dev

detect bot using images - asp.net

From Dev

Fix header row in repeater in ASP.NET

From Dev

C# ASP.Net - Issue when trying to bind labels within a Repeater, in my .cs code

Related Related

  1. 1

    NavigateUrl on Repeater ASP.net

  2. 2

    How to render two column layout using an asp.net repeater

  3. 3

    How can I bind the single LINQ object to ASP.NET Repeater Control

  4. 4

    ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

  5. 5

    ASP.NET Repeater - Eval() for bool?

  6. 6

    Using foreach with ASP.NET view engine inside a ASP: Repeater is not working

  7. 7

    repeater item command in asp.net

  8. 8

    How to dynamically bind asp.net repeater control to datasource

  9. 9

    asp.net repeater use template in javascript

  10. 10

    to disable a label of repeater on some condition in asp .net

  11. 11

    Using Bootstrap tabs with ASP NET repeater

  12. 12

    asp.net repeater for each row

  13. 13

    ASP.Net repeater control - using conditional statements

  14. 14

    asp.net repeater merge columns dynamically

  15. 15

    How To Make Slideshow Using ASP.NET Repeater

  16. 16

    Convert Bootstrap Carousel to ASP.Net Repeater

  17. 17

    Fix header row in repeater in ASP.NET

  18. 18

    NavigateUrl on Repeater ASP.net

  19. 19

    Changing the last datarow from a asp:repeater table if data is shown in asp:label using vb.net

  20. 20

    ASP.NET Converting repeater item to the textbox

  21. 21

    How to dynamically bind asp.net repeater control to datasource

  22. 22

    Repeater asp.net tag not working

  23. 23

    asp.net repeater merge columns dynamically

  24. 24

    Change the Image size before bind inside Repeater using c# asp.net.

  25. 25

    Convert Bootstrap Carousel to ASP.Net Repeater

  26. 26

    Conditional statement for Repeater Controll in ASP.NET

  27. 27

    detect bot using images - asp.net

  28. 28

    Fix header row in repeater in ASP.NET

  29. 29

    C# ASP.Net - Issue when trying to bind labels within a Repeater, in my .cs code

HotTag

Archive