Thomas answer will work based on your code. But I would suggest you also try using the ASP.Net and Sitecore server components.
This will avoid Null Reference errors, it will better support the Page Editor, and also simplify the work of your code.
You may have a repeater in your markup as follows:
<asp:Repeater ID="rptAdresses" runat="server"> <ItemTemplate> <span class="address"> <sc:Text id="scAddress" runat="server" Field="__Display Name" Item="<%#(Sitecore.Data.Items.Item)Container.DataItem%>"></sc:Text> </span> </ItemTemplate> </asp:Repeater>
And then bind the address for your code behind:
private void BindRepeater() { if (mainPage.TemplateID.ToString() != "{27A9692F-AE94-4507-8714-5BBBE1DB88FC}") { rptAdresses.Visible = false; } else { rptAdresses.DataSource = Sitecore.Context.Item.GetChildren(); rptAdresses.DataBind(); } }
Another thing I noticed is the line mainPage.TemplateID.ToString() != "{27A9692F-AE94-4507-8714-5BBBE1DB88FC}" . This is something you can also improve. Hard-coded identifiers are not a good estimate. You could create a class to hold these things, or better yet, you could think more about your design to avoid it.
amuses
source share