Accordionpane count number of divisions inside and store in an array

212 Views Asked by At
 <asp:accordionpane id="colors">

   <header> colors</header>

   <content>
    <div> blue </div>
    <div> red  </div>
    <div> gray </div>
   </content>

 </accordionpane>

is there a way to find no of divs and traverse the loop
and store there names in arrays say string colors{} = accordionpane.div("blue"), accordionpane.div("red"), accordionpane.div("gray")

or is there a way to find an accordionpane has div or not

1

There are 1 best solutions below

0
On

Make it runat=server (or even better- a Panel) if you want to access it on serverside. Otherwise you cannot traverse the colors.Controls since it's empty.

<asp:accordionpane id="colors">

   <header> colors</header>

   <content>
    <asp:Panel id="pnlBlue" runat="server"> blue </asp:Panel>
    <asp:Panel id="pnlRed" runat="server"> red  </asp:Panel>
    <asp:Panel id="pnlGray" runat="server"> gray </asp:Panel>
   </content>

</accordionpane>

Now this Linq query works:

Dim panelText = From p In colors.Controls.OfType(Of Panel)()
    Select p.Controls.OfType(Of LiteralControl)().First().Text.Trim()
Dim count As Int32 = panelText.Count()
Dim allColors = String.Join(",", panelText)