Hi nauna,
Please refer this code.
HTML
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>SubjectName</th>
<th>Marks</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="lblSubjectName" Text='<%#Eval("SubjectName") %>' runat="server" /></td>
<td><asp:Label ID="lblMarks" Text='<%#Eval("Marks") %>' runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>Total</td>
<td><asp:Label ID="lblTotal" runat="server" /></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] {
new DataColumn("SubjectName", typeof(string)),
new DataColumn("Marks",typeof(int)) });
dt.Rows.Add("English", 56);
dt.Rows.Add("Hindi", 75);
dt.Rows.Add("Maths", 61);
dt.Rows.Add("Science", 79);
Repeater1.DataSource = dt;
Repeater1.DataBind();
int totalMarks = dt.Select().Sum(p => Convert.ToInt32(p["Marks"]));
(Repeater1.Controls[Repeater1.Controls.Count - 1].Controls[0].FindControl("lblTotal") as Label).Text = totalMarks.ToString();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(1) {
New DataColumn("SubjectName", GetType(String)),
New DataColumn("Marks", GetType(Integer))})
dt.Rows.Add("English", 56)
dt.Rows.Add("Hindi", 75)
dt.Rows.Add("Maths", 61)
dt.Rows.Add("Science", 79)
Repeater1.DataSource = dt
Repeater1.DataBind()
Dim totalMarks As Integer = dt.[Select]().Sum(Function(p) Convert.ToInt32(p("Marks")))
TryCast(Repeater1.Controls(Repeater1.Controls.Count - 1).Controls(0).FindControl("lblTotal"), Label).Text = totalMarks.ToString()
End If
End Sub
Output
SubjectName | Marks |
English |
56 |
Hindi |
75 |
Maths |
61 |
Science |
79 |
Total |
271 |