Step 1
Create a table for storing your Image (Product) information, such as ProductID, Name ,Price, Quantity etc., which you want to show as product details on the homepage of a shopping cart.
Step 2
Create a web form for your web application.
Import Bootstrap line or manage NuGet packages to install bootstrap in your web form (right-click on web application --> Manage NuGet Packages-->install bootstrap).
Step 3
Add repeater in your form,
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <link href="Content/bootstrap.css" rel="stylesheet" />
- <title></title>
- <style>
- well{
- margin-top:20px;
- padding:2px,2px,2px,2px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div class="container" style="margin-top:10px">
- <div class="row">
- <asp:Repeater ID="RepeatImages" runat="server">
-
- <ItemTemplate>
- <div class="col-md-3">
- <div class="well" style="height:350px; width:350px;">
- <asp:Image ID="Image" runat="server" CssClass="align" style="height:200px; width:100%" ImageUrl='<%# DataBinder.Eval(Container,"DataItem.Image") %>' />
- <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.ImageID") %>'></asp:Label><br />
- </div>
- </div>
- </ItemTemplate>
-
- </asp:Repeater>
- </div>
- </div>
- </form>
- </body>
- </html>
Step 4
Now, add model to access database (right click on web application --> add new item-->ADO.NET entity data model (model.edmx)).
Create new connection Add database (Entity).
Choose table
By finishing this you will get access to your database.
Step 5
Fetch the data from table to send it to repeater,
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using upload_image.model;
-
- namespace upload_image
- {
- public partial class repeater : System.Web.UI.Page
- {
- userEntities db = new userEntities();
- protected void Page_Load(object sender, EventArgs e)
- {
- var data = (from a in db.ImageUploads select a).ToList();
-
- RepeatImages.DataSource = data;
- RepeatImages.DataBind();
-
- }
- }
- }
I am using LINQ for fetching data.
var data = (from a in db.ImageUploads select a).ToList();
Now, you will get UI as follows,
You can design more using external CSS as well.
Thank you.