Hi Joey,
Please refer the below sample.
Database
CREATE TABLE [dbo].[Vegetables](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NULL,
[PricePerKg] [varchar](50) NULL,
[Quantity] [int] NULL,
CONSTRAINT [PK_Vegetables] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
INSERT [Vegetables] ([Name], [PricePerKg], [Quantity]) VALUES ('Potato', N'30', 20)
INSERT [Vegetables] ([Name], [PricePerKg], [Quantity]) VALUES ('Onion', N'35', 50)
INSERT [Vegetables] ([Name], [PricePerKg], [Quantity]) VALUES ('Beetroot', N'60', 55)
INSERT [Vegetables] ([Name], [PricePerKg], [Quantity]) VALUES ('Carrot', N'65', 10)
HTML
<asp:Repeater ID="rptVegetables" runat="server">
<HeaderTemplate>
<table>
<table>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>PricePerKg</th>
<th>Quantity</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%#Eval("Id") %>' runat="server"></asp:Label></td>
<td>
<asp:Label ID="lblName" Text='<%#Eval("Name") %>' runat="server"></asp:Label></td>
<td>
<asp:Label ID="lblPricePerKg" Text='<%#Eval("PricePerKg") %>' runat="server"></asp:Label></td>
<td>
<asp:Label ID="lblQuantity" Text='<%#Eval("Quantity") %>' runat="server"></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespace
using System.Linq;
Code
#region Events
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
CustomersEntities entities = new CustomersEntities();
var Vegetables = from p in entities.Vegetables
select new
{
Id = p.ID,
Name = p.Name,
PricePerKg = p.PricePerKg,
Quantity = p.Quantity
};
rptVegetables.DataSource = Vegetables.ToList();
rptVegetables.DataBind();
}
}
#endregion
Screenshot
