This article explains how to create an image gallery in ASP.NET using the FileUpload control and a DataList.
I have designed the form and added the following two controls:
- Fileupload control: control to upload the image file to a folder and the information is saved into a SQL Server database table.
- DataList: to display the image in a repeating column row.
The following is the step-by-step procedure to create an Image Gallery in ASP.NET C# using a FileUpload control and a DataList.
Step 1: Create a table in your database as below:

The Image id is the identity column.
Step 2: Design the form as follows:
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ImageGallery.aspx.cs" Inherits="Image_Library.ImageGallery" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td colspan="3">
- <h2>
- Image Gallery</h2>
- </td>
- </tr>
- <tr>
- <td>
- Upload Image
- </td>
- <td>
- <asp:FileUpload ID="imgFileUpload" runat="server" />
- </td>
- <td>
- <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
- </td>
- </tr>
- </table>
- </div>
- <div id="divImageList" runat="server">
- <asp:DataList ID="dtListImageGallery" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
- Width="50%" BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px">
- <ItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Eval("ImageName") %>' Font-Bold="True"
- Font-Size="10pt" ForeColor="#336699" Width="100%" />
- <br />
- <asp:Image Width="100" ID="imgGallery" ImageUrl='<%# Bind("ImagePath", "~/ImageGallery/{0}") %>'
- runat="server" />
- </ItemTemplate>
- <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
- </asp:DataList>
- </div>
- </form>
- </body>
- </html>


Join the conversation! Your thoughts help the community grow.