Hi Tevin,
Check this example. Now please take its reference and correct your code.
HTML
C#
<asp:RadioButtonList ID="optMetric" runat="server" AutoPostBack="true" OnSelectedIndexChanged="optMetric_SelectedIndexChanged">
<asp:ListItem> Kilograms</asp:ListItem>
<asp:ListItem> Grams</asp:ListItem>
</asp:RadioButtonList>
<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>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Part Weight (g)</th>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Part Weight (Kg)</th>
<%} %>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Sprue Weight (g)</th>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Sprue Weight (Kg)</th>
<%} %>
<th>Tolerance %</th>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Bom Weight (g)</th>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Bom Weight (Kg)</th>
<%} %>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Variance To Syspro (g)</th>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Variance To Syspro (Kg)</th>
<%} %>
<th>Variance To Syspro (%)</th>
<th>Out Of Spec</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<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>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightGram")%>' runat="server" ID="lblPartWeightGram" /></td>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightKg")%>' runat="server" ID="lblPartWeightKg" /></td>
<%} %>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightGram")%>' runat="server" ID="lblSprueWeightGram" /></td>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightKg")%>' runat="server" ID="lblSprueWeightKg" /></td>
<%} %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "TolerancePercentage")%>' runat="server" ID="lblTolerancePercentage" /></td>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightGrams")%>' runat="server" ID="lblBomWeightGrams" /></td>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightKg")%>' runat="server" ID="lblBomWeightKG" /></td>
<%} %>
<%if (this.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproGram")%>' runat="server" ID="lblVarianceToSysproGram" /></td>
<%} %>
<%if (this.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproKg")%>' runat="server" ID="lblVarianceToSysproKg" /></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>
VB.Net
<asp:RadioButtonList ID="optMetric" runat="server" AutoPostBack="true" OnSelectedIndexChanged="optMetric_SelectedIndexChanged">
<asp:ListItem> Kilograms</asp:ListItem>
<asp:ListItem> Grams</asp:ListItem>
</asp:RadioButtonList>
<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>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Part Weight (g)</th>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Part Weight (Kg)</th>
<%} %>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Sprue Weight (g)</th>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Sprue Weight (Kg)</th>
<%} %>
<th>Tolerance %</th>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Bom Weight (g)</th>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Bom Weight (Kg)</th>
<%} %>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Variance To Syspro (g)</th>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<th>Variance To Syspro (Kg)</th>
<%} %>
<th>Variance To Syspro (%)</th>
<th>Out Of Spec</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<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>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightGram")%>' runat="server" ID="lblPartWeightGram" /></td>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightKg")%>' runat="server" ID="lblPartWeightKg" /></td>
<%} %>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightGram")%>' runat="server" ID="lblSprueWeightGram" /></td>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightKg")%>' runat="server" ID="lblSprueWeightKg" /></td>
<%} %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "TolerancePercentage")%>' runat="server" ID="lblTolerancePercentage" /></td>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightGrams")%>' runat="server" ID="lblBomWeightGrams" /></td>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightKg")%>' runat="server" ID="lblBomWeightKG" /></td>
<%} %>
<%if (Me.Metric == "grams" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproGram")%>' runat="server" ID="lblVarianceToSysproGram" /></td>
<%} %>
<%if (Me.Metric == "kilograms" || string.IsNullOrEmpty(this.Metric))
{ %>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproKg")%>' runat="server" ID="lblVarianceToSysproKg" /></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 string Metric = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
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("PartWeightKg", typeof(double));
dt.Columns.Add("SprueWeightGram", typeof(double));
dt.Columns.Add("SprueWeightKg", typeof(double));
dt.Columns.Add("TolerancePercentage");
dt.Columns.Add("BomWeightGrams", typeof(double));
dt.Columns.Add("BomWeightKg", typeof(double));
dt.Columns.Add("VarianceToSysproGram", typeof(double));
dt.Columns.Add("VarianceToSysproKg", typeof(double));
dt.Columns.Add("VarianceToSysproPct");
dt.Columns.Add("IsOutOfSpec");
dt.Rows.Add(DateTime.Now, "123", "Desc 1", 1000, 1, 9000, 9, "", 100, .1, 100, .1, "", "");
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)
{
}
protected void optMetric_SelectedIndexChanged(object sender, EventArgs e)
{
Metric = optMetric.SelectedItem.Text.Trim().ToLower();
BindRepeater();
}
VB.Net
Protected Metric As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindRepeater()
End If
End Sub
Private Sub BindRepeater()
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("PartWeightKg", GetType(Double))
dt.Columns.Add("SprueWeightGram", GetType(Double))
dt.Columns.Add("SprueWeightKg", GetType(Double))
dt.Columns.Add("TolerancePercentage")
dt.Columns.Add("BomWeightGrams", GetType(Double))
dt.Columns.Add("BomWeightKg", GetType(Double))
dt.Columns.Add("VarianceToSysproGram", GetType(Double))
dt.Columns.Add("VarianceToSysproKg", GetType(Double))
dt.Columns.Add("VarianceToSysproPct")
dt.Columns.Add("IsOutOfSpec")
dt.Rows.Add(DateTime.Now, "123", "Desc 1", 1000, 1, 9000, 9, "", 100, .1, 100, .1, "", "")
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 Sub
Protected Sub rpComponentWeightResults_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
End Sub
Protected Sub optMetric_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Metric = optMetric.SelectedItem.Text.Trim().ToLower()
BindRepeater()
End Sub
Screenshot