I am looking for an elegant solution for removing content from an ASP.Net page if no data has been set. Let me explain this a little more.
I have some blocks of data on a page that contain some sub-sections with individual values in them. If no data has been set for one of the values I need to hide it (so it does not take up space). Also, if none of the values within a sub-section have been set, it needs to be hidden as well. Finally if none of the sub-sections are visible within the block/panel, then I need to hide the entire thing.
The layout is implemented using nested Panels/DIVs
<Panel id="block">
<Panel id="sub1">
<Panel id="value1-1">blah</Panel>
<Panel id="value1-2">blah</Panel>
</Panel>
<Panel id="sub2">
<Panel id="value2-1">blah</Panel>
<Panel id="value2-2">blah</Panel>
</Panel>
</panel>
I am wondering if anyone has any decent ideas on implementing something like this without writing a bunch of nested If..Else statements, and without creating a bunch of custom controls. Whatever I implement needs to be robust enough to handle changes in the markup without constantly manipulating the codebehind.
I am hoping there is a way to do this through some simple markup changes (custom attribute) and a recursive function call on PageLoad or PreRender.
Any help is greatly appreciated.
EDIT:
Ok so what makes this tricky is that there might be other controls inside the sub-sections that do not factor into the hiding and showing of the controls. And each value panel could potentially have controls in it that do not factor into whether or not it is shown. Example:
<Panel id="sub2">
<Image id="someImage" src="img.png" />
<Panel id="value2-1">
<Label>blah</Label>
<TextBox id="txtValue" />
</Panel>
<Panel id="value2-2">blah</Panel>
</Panel>
This is an over simplified example, but not far off from what I have to worry about.