Hiding and showing content in ASP.Net based on value
I am looking for an elegant solution to remove content from an ASP.Net page if no data is set. Let me explain this a little more.
I have several blocks of data on a page that contain some subsections with separate values ββin them. If no data has been specified for one of the values, I need to hide it (so it doesn't take up space). Also, if none of the values ββin the sub-series have been set, it should also be hidden. Finally, if none of the subsections appear inside the block / panel, then I need to hide everything.
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'm wondering if anyone has any decent ideas for implementing something like this without creating a bunch of nested If..Else statements and creating a bunch of custom controls. No matter what I implement, it needs to be robust enough to handle the markup changes without constantly manipulating the code.
I hope there is a way to do this through some simple markup changes (custom attribute) and a recursive function call on the PageLoad or PreRender page.
Any help is greatly appreciated.
EDIT:
Ok, so what makes this tricky is that there may be other controls in the subsectors that don't affect hiding and showing the controls. And each value bar could potentially have controls in it that don't affect the display or not. 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 a more simplified example, but just around the corner, which I should be worried about.
source to share
recursive traversal can be avoided if you can write functions to return true / false for each group, eg.
<Panel id="block" runat="server" visible="<%=IsBlockVisible%>">
<Panel id="sub1" runat="server" visible="<%=IsSubVisible(1)%>">
<Panel id="value1-1">blah</Panel>
<Panel id="value1-2">blah</Panel>
</Panel>
<Panel id="sub2" runat="server" visible="<%=IsSubVisible(2)%>">
<Panel id="value2-1">blah</Panel>
<Panel id="value2-2">blah</Panel>
</Panel>
</panel>
source to share