c# - Use system.web.UI.Control.FindControl to retrieve multiple controls -


i've got webpage repeater. have single repeater shows articles

<asp:repeater runat="server" id="rptarticles" datasource="<%# currentarticles %>"> 

inside these articles few checkboxes can use check articles , actions them.

to retrieve , return checkboxes have following methods

    protected readonly property articlerepeater repeater                     return directcast(findcontrol("rptarticles"), repeater)         end     end property      protected overridable function getselectedarticles() string         dim checkboxes htmlinputcheckbox() = dataconvert.findcontrolsbytype(of htmlinputcheckbox)(articlerepeater, true)         dim selectedvalues string() = (from cbx in checkboxes cbx.checked select cbx.value).toarray         return string.join(";", selectedvalues)     end function 

these methods work @ moment.

but want filter articles little bit more have repeater inside initial repeater, filters them , shows them specific filter. code looks now.

<asp:repeater runat="server" id="rptarticles" datasource="<%# currentarticles %>">     <asp:repeater runat="server" id="childrepeater" datasource="<%# filter(container.dataitem) %>">     

but getselectedarticles function doesn't work anymore. rptarticles repeater doesn't have control of checkboxes anymore, hence can't retreive them.

does know how can replace property "articlerepeater" in such way can use again or returns child repeaters?

note: tried swapping names around, because have multiple childrepeaters findcontrol function doesn't work anymore.

answers can given in either vb.net or c# can convert these languages pretty easy

edit: forgot mention. still has work legacy code uses old single repeater

here suggestion of how possibly work around. please note have never seen findcontrolsbytype method before, going assume using similar 1 (taken here):

public static list<t> findcontrolsbytype<t>(this control ctrl) {   return ctrl.getchildren().oftype<t>().tolist(); } 

this version missing second parameter, boolean, purpose of yet unclear me.

the idea retrieve child repeaters, , each of them retrieve checkboxes inside. combined should give checkboxes inside rptarticles:

var childrepeaters = dataconvert.findcontrolsbytype<repeater>(articlerepeater); var checkboxes = childrepeaters.selectmany(r => dataconvert.findcontrolsbytype<htmlinputcheckbox>(r)).tolist(); 

note code using linq's selectmany. checkboxes should contain checkboxes found inside outer repeater


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -