c# - Find control in Web Forms inside a repeater -


i'm unable find literal inside repeater in usercontrol.

i have following usercontrol:

<nav role="navigation"> <ul>     <li><a href="/"<asp:literal id="litnavhomeactive" runat="server" />>home</a></li> <asp:repeater id="rpt_navitem" runat="server" onitemdatabound="rpt_onitemdatabound"> <itemtemplate>     <li><a href="/<asp:literal id="lit_url" runat="server" />/"<asp:literal id="lit_navactive" runat="server" />><asp:literal id="lit_title" runat="server" /></a></li> </itemtemplate> </asp:repeater> </ul> <div class="cb"></div> </nav> 

this placed inside masterpage , contentpage, i'm trying find "lit_navactive" , hide it.

i using this:

repeater rpt = ((theme)page.master).findcontrol("navigation").findcontrol("rpt_navitem") repeater; literal lit = rpt.findcontrol("lit_navactive"); if (lit != null) { lit.visible = false; } 

and not working, if rpt.visible = false; works fine in hiding whole repeater, i'm close fail find literal (lit_navactive) inside repeater. ideas?

you need find control on repeateritem, not on repeater self

foreach (var item in rpt.items) {    literal lit = item.findcontrol("lit_navactive");    if (lit != null) { lit.visible = false; } } 

remember repeater "repeats" items, there may multiple literals within repeater. above code hides literals.

if need hide "specific" on, in loop, should apply condition , decide whether show or hide it.

alternatively consider using itemdatabound event of repeater.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -