<html>
<head>
<title>Panel Control Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( object src, EventArgs e ) {
// show/hide panel contents
myPanel.Visible = Check1.Checked ? false : true;
// generate label controls
int numlabels = int.Parse ( DropDown1.SelectedItem.Value );
for ( int i = 1; i <= numlabels; i++ ) {
myPanel.Controls.Add ( new LiteralControl ( "<p>" ) );
Label l = new Label ( );
l.Text = "Label" + i.ToString ( );
l.ID = "Label" + i.ToString ( );
myPanel.Controls.Add ( l );
}
// generate textbox controls
int numtexts = int.Parse ( DropDown2.SelectedItem.Value );
for ( int i = 1; i <= numtexts; i++ ) {
myPanel.Controls.Add ( new LiteralControl ( "<p>" ) );
TextBox t = new TextBox ( );
t.Text = "TextBox" + i.ToString ( );
t.ID = "TextBox" + i.ToString ( );
myPanel.Controls.Add ( t );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Panel Control Example</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:panel id="myPanel" runat="server"
backcolor="#eeeeee"
width="300px">
<p>Here is some content ...</p>
</asp:panel>
<br>
<table cellpadding=3>
<tr>
<td>Generate Labels:</td>
<td><asp:dropdownlist id="DropDown1" runat="server">
<asp:listitem value=1>1</asp:listitem>
<asp:listitem value="2">2</asp:listitem>
<asp:listitem value=3>3</asp:listitem>
<asp:listitem value="4">4</asp:listitem>
<asp:listitem value="5">5</asp:listitem>
</asp:dropdownlist></td>
<tr>
<td>Generate TextBoxes:</td>
<td><asp:dropdownlist id="DropDown2" runat="server">
<asp:listitem value=1>1</asp:listitem>
<asp:listitem value="2">2</asp:listitem>
<asp:listitem value=3>3</asp:listitem>
<asp:listitem value="4">4</asp:listitem>
<asp:listitem value="5">5</asp:listitem>
</asp:dropdownlist></td></tr>
<tr>
<td colspan=2 align="center"><asp:checkbox id="Check1" text="Hide Panel" runat="server" /></td></tr>
<tr>
<td colspan=2 align="center"><asp:button text="Refresh Panel" runat="server" /></td></tr>
</table>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>