I have a repeater control with headers and rows and the rows have labels in.
When i debug my code for ItemDataBound then i see that it does not check the rows it only checks my headers. What could be the problem.
ItemDataBound Code:
'Gram Headers
If e.Item.ItemType = ListItemType.Header Then
TryCast(e.Item.FindControl("PartWeightGramHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("SprueWeightGramHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("BomWeightGramHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("VarianceToSysproGramHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
End If
'Gram Columns
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
TryCast(e.Item.FindControl("PartWeightGramCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("SprueWeightGramCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("BomWeightGramCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
TryCast(e.Item.FindControl("VarianceToSysproGramCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Kilograms", False, True)
End If
'Kilogram Headers
If e.Item.ItemType = ListItemType.Header Then
TryCast(e.Item.FindControl("PartWeightKgHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("SprueWeightKgHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("BomWeightKgHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("VarianceToSysproKgHeader"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
End If
'Kilogram Columns
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
TryCast(e.Item.FindControl("PartWeightKgCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("SprueWeightKgCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("BomWeightKgCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
TryCast(e.Item.FindControl("VarianceToSysproKgCol"), HtmlTableCell).Visible = If(optMetric.SelectedItem.Text = "Grams", False, True)
End If
Below is my repeater control:
<asp:Repeater ID="rpComponentWeightResults" OnItemDataBound="ItemDataBound" runat="server">
<HeaderTemplate>
<table class="table table-striped table-bordered table-hover table-condensed" border="1">
<tr>
<th>Date Captured</th>
<th>Stock Code</th>
<th>Description</th>
<th id="PartWeightGramHeader" runat="server">Part Weight (g)</th>
<th id="SprueWeightGramHeader" runat="server">Sprue Weight (g)</th>
<th id="PartWeightKgHeader" runat="server">Part Weight (kg)</th>
<th id="SprueWeightKgHeader" runat="server">Sprue Weight (kg)</th>
<th>Tolerance %</th>
<th id="BomWeightGramHeader" runat="server">Bom Weight (g)</th>
<th id="BomWeightKgHeader" runat="server">Bom Weight (kg)</th>
<th id="VarianceToSysproGramHeader" runat="server">Variance To Syspro (g)</th>
<th id="VarianceToSysproKgHeader" runat="server">Variance To Syspro (kg)</th>
<th>Variance To Syspro (%)</th>
<th>Out Of Spec</th>
</tr>
</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>
<td id="PartWeightGramCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightGram", "{0:f}")%>' runat="server" ID="lblPartWeightGram" />
</td >
<td id="SprueWeightGramCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightGram", "{0:f}")%>' runat="server" ID="lblSprueWeightGram" />
</td>
<td id="PartWeightKgCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "PartWeightKg", "{0:f}")%>' runat="server" ID="lblPartWeightKg" />
</td>
<td id="SprueWeightKgCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "SprueWeightKg", "{0:f}")%>' runat="server" ID="lblSprueWeightKg" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "TolerancePercentage")%>' runat="server" ID="lblTolerancePercentage" />
</td>
<td id="BomWeightGramCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightGram", "{0:f}")%>' runat="server" ID="lblBomWeightGram" />
</td>
<td id="BomWeightKgCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "BomWeightKg", "{0:f}")%>' runat="server" ID="lblBomWeightKg" />
</td>
<td id="VarianceToSysproGramCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproGram", "{0:f}")%>' runat="server" ID="lblVarianceToSysproGram" />
</td>
<td id="VarianceToSysproKgCol" runat="server">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproKg", "{0:f}")%>' runat="server" ID="lblVarianceToSysproKg" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "VarianceToSysproPct")%>' runat="server" ID="lblVarianceToSysproPct" />
</td>
<td>
<asp:Label Text='<%# SetText(DataBinder.Eval(Container.DataItem, "IsOutOfSpec").ToString()) %>' runat="server" ID="lblIsOutOfSpec" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>