Nested repeater controls show/hide?

S

sorCrer

Hi All,

Posted after extensive searching!

I have a nested repeater control as follows: (Simplified ;-))

<table>
<asp:repeater id=parent onItemDataBound=createChild>
<tr><td>Level 1</td></tr>
<asp:repeater id=child>
<tr id=childrow><td>Level 2</td></tr>
</asp:repeater>
</asp:repeater>
</table>

They are both created from a SQL query. I would simply like to not
display the child if the parent meets a condition. I would therefore
like to add a style="display: none;" attribute to the row 'childrow'.

How can I access the child of the parent in the onItemDataBound event,
which is when it gets created? I can access anything outside the child
repeater but not inside it.

(As a side issues all ID's are dynamically created at databind time
for use with Javascript etc.)

Help would be much appreciated!

Thanks
John Sourcrer
 
K

Karl Seguin

You say you can't access anthing inside the child repeater, but can you
access the child repeater itself ala e.Item.FindControl("child") if so,
why not just set it's visiblility to false, not bind it and voila?

Karl
 
S

sorCrer

Hi Karl,

Thanks for your post but this I can do! What I am trying to do is bind
the data, then add a style attribute that sets its display property to
false. I need to do this because I want to dynamically display the
children when a user clicks on a +/- icon. Like any standard tree type
menu.

Any ideas?

Interesting articles on your site BTW.

Regards
John
 
K

Karl Seguin

John:
You could simply use
http://www.denisbauer.com/ASPNETControls/HierarGrid.aspx

You'll likely have some difficulty doing this with a repeater, namely
because I assume you have something like:

<HeaderTemplate>
<table border="0" ...>
</headertemplate>
<itemTempalte>...</ItemTEmplate>
<footerTempalte</table></footerTemplate>

and you need to programatically set the visibility style of the <Table>
which you won't be able to find using FindControl since it isn't a server
control...you can't simply add a runat=server (I think) because it doesn't
think it has a closing </table> tag.

What you could do is place the table control outside the child repeater:
<ItemTemplate>
<td><%# DataBinder.Eval(Container.DataItem ,"Name")%>
<table id="x" runat="server">
<asp:Repeater ID="inner" DataSource='...' Runat="server">
<ItemTemplate>
<tr><td><%# DataBinder.Eval(Container.DataItem,
"Amount")%></td></td>
</ItemTemplate>
</asp:Repeater>
</table>>
</td>
</ItemTemplate>

which you could then access it from the outer repeater...or simply use:

<table style='visibility:<%# GetVisibility(Container.DataItem) %>'> or
something...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


sorCrer said:
Hi Karl,

Thanks for your post but this I can do! What I am trying to do is bind
the data, then add a style attribute that sets its display property to
false. I need to do this because I want to dynamically display the
children when a user clicks on a +/- icon. Like any standard tree type
menu.

Any ideas?

Interesting articles on your site BTW.

Regards
John

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top