Hi Tevin,
Use DataTable Compute function to calculate Aggregate function such as SUM, COUNT, MIN, MAX and AVG.
Check this example. Now please take its reference and correct your code.
HTML
<asp:Panel ID="pnlSearchResults" CssClass="panel panel-success" runat="server">
<div class="panel-heading">
<h3 class="panel-title ">Search Results</h3>
</div>
<div class="panel-body">
<asp:Repeater ID="rpComponentWeightResults" runat="server" OnItemCommand="rpComponentWeightResults_ItemCommand">
<HeaderTemplate>
<table class="table table-striped table-bordered table-hover table-condensed" border="1">
<thead>
<tr>
<th>Date Captured</th>
<th>Stock Code</th>
<th>Description</th>
<th>Part Weight (g)</th>
<th>Sprue Weight (g)</th>
<th>Tolerance %</th>
<th>Bom Weight (g)</th>
<th>Variance To Syspro (g)</th>
<th>Variance To Syspro (%)</th>
<th>Out Of Spec</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr runat="server" id="employeeInfo">
<td>
<asp:Label Text='<%# Eval("CapturedDateTime", "{0: dd/MM/yyyy}")%>' runat="server" ID="lblCaptureDate" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "StockCode")%>' runat="server" ID="lblStockCode" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "LongDesc")%>' runat="server" ID="lblLongDesc" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightGram")%>' runat="server" ID="lblPartWeightGram" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightGram")%>' runat="server" ID="lblSprueWeightGram" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "TolerancePercentage")%>' runat="server" ID="lblTolerancePercentage" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightGrams")%>' runat="server" ID="lblBomWeightKG" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproGram")%>' runat="server" ID="lblVarianceToSysproGram" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproPct")%>' runat="server" ID="lblVarianceToSysproPct" /></td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "IsOutOfSpec")%>' runat="server" ID="lblIsOutOfSpec" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
<div class="panel-footer">
Part Weight : <asp:Label ID="lblPartWeightGram" runat="server" /><br />
Sprue Weight : <asp:Label ID="lblSprueWeightGram" runat="server" /><br />
Bom Weight :
<asp:Label ID="lblBomWeightGrams" runat="server" /><br />
Variance To Syspro : <asp:Label ID="lblVarianceToSysproGram" runat="server" />
</div>
</asp:Panel>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("CapturedDateTime");
dt.Columns.Add("StockCode");
dt.Columns.Add("LongDesc");
dt.Columns.Add("PartWeightGram", typeof(double));
dt.Columns.Add("SprueWeightGram", typeof(double));
dt.Columns.Add("TolerancePercentage");
dt.Columns.Add("BomWeightGrams", typeof(double));
dt.Columns.Add("VarianceToSysproGram", typeof(double));
dt.Columns.Add("VarianceToSysproPct");
dt.Columns.Add("IsOutOfSpec");
dt.Rows.Add(DateTime.Now, "123", "Desc 1", 100, 99, "", 1, 1, "", "");
dt.Rows.Add(DateTime.Now, "124", "Desc 2", 200, 100, "", 100, 100, "", "");
dt.Rows.Add(DateTime.Now, "125", "Desc 3", 300, 150, "", 150, 150, "", "");
rpComponentWeightResults.DataSource = dt;
rpComponentWeightResults.DataBind();
lblPartWeightGram.Text = Convert.ToDouble(dt.Compute("AVG(PartWeightGram)", string.Empty)).ToString("N2");
lblSprueWeightGram.Text = Convert.ToDouble(dt.Compute("AVG(SprueWeightGram)", string.Empty)).ToString("N2");
lblBomWeightGrams.Text = Convert.ToDouble(dt.Compute("SUM(BomWeightGrams)", string.Empty)).ToString("N2");
lblVarianceToSysproGram.Text = Convert.ToDouble(dt.Compute("SUM(VarianceToSysproGram)", string.Empty)).ToString("N2");
}
}
protected void rpComponentWeightResults_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles me.Load
If Not IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.Add("CapturedDateTime")
dt.Columns.Add("StockCode")
dt.Columns.Add("LongDesc")
dt.Columns.Add("PartWeightGram", GetType(Double))
dt.Columns.Add("SprueWeightGram", GetType(Double))
dt.Columns.Add("TolerancePercentage")
dt.Columns.Add("BomWeightGrams", GetType(Double))
dt.Columns.Add("VarianceToSysproGram", GetType(Double))
dt.Columns.Add("VarianceToSysproPct")
dt.Columns.Add("IsOutOfSpec")
dt.Rows.Add(DateTime.Now, "123", "Desc 1", 100, 99, "", 1, 1, "", "")
dt.Rows.Add(DateTime.Now, "124", "Desc 2", 200, 100, "", 100, 100, "", "")
dt.Rows.Add(DateTime.Now, "125", "Desc 3", 300, 150, "", 150, 150, "", "")
rpComponentWeightResults.DataSource = dt
rpComponentWeightResults.DataBind()
lblPartWeightGram.Text = Convert.ToDouble(dt.Compute("AVG(PartWeightGram)", String.Empty)).ToString("N2")
lblSprueWeightGram.Text = Convert.ToDouble(dt.Compute("AVG(SprueWeightGram)", String.Empty)).ToString("N2")
lblBomWeightGrams.Text = Convert.ToDouble(dt.Compute("SUM(BomWeightGrams)", String.Empty)).ToString("N2")
lblVarianceToSysproGram.Text = Convert.ToDouble(dt.Compute("SUM(VarianceToSysproGram)", String.Empty)).ToString("N2")
End If
End Sub
Protected Sub rpComponentWeightResults_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
End Sub
Screenshot