List with images from code behind (ASP.NET C#) to image overview in ASPX [closed]

拈花ヽ惹草 提交于 2019-12-05 18:26:20

Question 1

You can use a gridview to display the images, not sure exactly what type of list you have in your code behind so I've created a simple List<Images> where Images is a class with two properties Name and URL, but I trust you can change the code accordingly to work with your list:

ASPX:

<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:ImageField DataImageUrlField="URL" HeaderText="Image" 
        ControlStyle-Height="150" ControlStyle-Width="120" />
    </Columns>
</asp:GridView>

Code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        List<Image> images = new List<Image>
        {
            new Image("Picture 1","~/Images/Pic1.jpg"),
            new Image("Picture 2","~/Images/Pic2.jpg"),
        };

        gvImages.DataSource = images;
        gvImages.DataBind();
    }
}

public class Image
{
    public Image(string name, string url)
    {
        this.name = name;
        this.url = url;
    }

    private string name;
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    private string url;
    public string URL
    {
        get { return url; }
        set { url = value; }
    }
}

Question 2

Have a look at jQuery Galleria it has functionality to list all the thumbnails as well as the next and previous buttons.And if you want to display the name or any other description of the image when hovering over the image just change the title HTML attribute to the desired value:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!