What I am trying to do is access a column (which has the header title "Add to Shopping List") inside a repeater (areaRepeater) that is inside another repeater (locationRepeater). I want to hide it if a checkbox is checked. However, despite how things are setup, the column is never hidden. I'm not sure what I'm missing here...or maybe I'm going about it the wrong way?
Here is the piece of code that I am trying to use to hide the column in the areaRepeater table. I can hide the submitBtn button successfully, but that button is not inside a repeater.
Sitecore.Data.Fields.CheckboxField checkBox = ProductGroup.Fields["Shopping Disabled"];
if (checkBox.Checked)
{
submitBtn.Visible = false;
Repeater rpt1 = (Repeater)FindControl("locationRepeater");
Response.Write("a ");
foreach (RepeaterItem rep in rpt1.Items)
{
Response.Write("1 ");
Repeater areaRepeater = (Repeater)rep.FindControl("areaRepeater");
foreach (RepeaterItem areaRep in areaRepeater.Items)
{
Response.Write("2 ");
if (showField() == false)
{
Label lbl1 = (Label)areaRep.FindControl("litCol");
CheckBox check = (CheckBox)areaRep.FindControl("LineQuantity");
lbl1.Visible = false;
check.Visible = false;
}
}
}
}
This is the designer code for both repeaters. I tried setting the visibility of the label for the header and the checkbox with a function called showField() but it is never called, even though it does return the correct bool value:
<asp:Repeater ID="locationRepeater" runat="server" OnItemDataBound="SetInner">
<ItemTemplate>
<div class="LocationName">
<%# Eval("SecOpen") %><%# Eval("LocationName")%> <%# Eval("SecClose") %>
</div>
<asp:Repeater ID="areaRepeater" runat="server">
<HeaderTemplate>
<div class="headerRow">
<div class="header">
<div class="thumb"><p></p></div>
<div class="headerField name"><p class="hField">Product</p></div>
<div class="headerField sku"><p class="hField">SKU</p></div>
<div class="headerField size"><p class="hField">Size</p></div>
<div class="headerField case"><p class="hField">Case Pack</p></div>
<div class="headerField use"><p class="hField">Use With</p></div>
<div id="shoppingHeader" class="headerField qty" runat="server"><p class="headerfield qty hField"><asp:Label id="listCol" runat="server" visible='<%# showField() %>' Text="Add To Shopping List" /> </p></div>
</div>
</div>
</HeaderTemplate>
<ItemTemplate>
<asp:placeholder id="LocationAreaHeader" runat="server" visible='<%# (Eval("AreaName").ToString().Length == 0 ? false : true) %>' ><h3> <%# Eval("AreaName") %></h3></asp:placeholder>
<asp:placeholder id="ProductTable" runat="server" visible='<%# (Eval("ProductName").ToString().Length == 0 ? false : true) %>' >
<div class="table">
<div class="row">
<div class="thumb"><%# Eval("Charm") %></div>
<div class="field name"><p class="pField"> <%# Eval("ThumbOpen") %><%# Eval("ProductName") %><%# Eval("ThumbClose") %></p> </div>
<div class="field sku"><p class="pField"> <%# Eval("Sku") %> </p></div>
<div class="field size"><p class="pField"> <%# Eval("Size") %></p></div>
<div class="field case"><p class="pField"> <%# Eval("CasePack") %> </p></div>
<div class="field use"><p class="pField"> <%# Eval("UseWith") %> </p></div>
<div id="shopping" class="field qty" runat="server"><p class="pField"> <asp:checkbox visible='<%# showField() %>' id="LineQuantity" runat="server" /></p></div>
</div>
</div>
<asp:Label id="productID" text='<%# Eval("productID") %>' visible="false" runat="server" />
</asp:placeholder>
<!-- Stored values -->
<asp:Label id="SkuID" runat="server" text='<%# Eval("SkuID") %>' visible="true" />
<asp:Label id="masterSku" runat="server" text='<%# Eval("masterSku") %>' visible="false" />
<asp:Label id="masterName" runat="server" text='<%# Eval("masterName" ) %>' visible="false" />
<asp:Label ID="test" visible="false" runat="server" text='<%# Eval("AreaID") %>' />
</ItemTemplate>
</asp:Repeater>
<asp:Label ID="refID" visible="false" runat="server" text='<%# Eval("LocationID") %>' />
</ItemTemplate>
</asp:Repeater>
This is the showField() function:
protected bool showField()
{
bool retVal = true;
Item CurrentItem = Sitecore.Context.Item;
Item HomeItem = ScHelper.FindAncestor(CurrentItem, "Market");
if (HomeItem != null)
{
Item ProductGroup = HomeItem.Axes.SelectSingleItem(@"child::*[@@templatename='MarketOfficeBuildigProductMap']");
if (ProductGroup != null)
{
Sitecore.Data.Fields.CheckboxField checkBox = ProductGroup.Fields["Shopping Disabled"];//curently returns true
ShoppingDisabled.Value = checkBox.Checked.ToString();
if (checkBox.Checked == true)
{
retVal = false;
}
}
}
return retVal;
}