Dynamically control the explicit and hidden panel and control its content

Source: Internet
Author: User

The panel control on the first floor is a container of other controls. This control is especially useful if you plan to generate multiple controls programmatically or hide/display a group of controls.

The following example shows how to use the panel control to generate controls programmatically and hide/display a group of controls.

<% @ Page Language = "C #" %>
<HTML>
<Head>

<SCRIPT runat = "server">

Void page_load (Object sender, eventargs e ){

// Show or hide the Panel contents.

If (check1.checked ){
Panel1.visible = false;
}
Else {
Panel1.visible = true;
}

// Generate the label controls.

Int numlabels = int32.parse (dropdown1.selecteditem. value );

For (INT I = 1; I <= numlabels; I ++ ){
Label L = new label ();
L. Text = "label" + (I). tostring ();
L. ID = "label" + (I). tostring ();
Panel1.controls. Add (L );
Panel1.controls. Add (New literalcontrol ("<br> "));
}

// Generate the textbox controls.

Int numtexts = int32.parse (dropdown2.selecteditem. value );

For (INT I = 1; I <= numtexts; I ++ ){
Textbox T = new Textbox ();
T. Text = "textbox" + (I). tostring ();
T. ID = "textbox" + (I). tostring ();
Panel1.controls. Add (t );
Panel1.controls. Add (New literalcontrol ("<br> "));
}
}

</SCRIPT>

</Head>
<Body>

<H3> panel example
<Form runat = Server>

<Asp: Panel id = "Panel1" runat = "server"
Backcolor = "gainsboro"
Height = "200px"
Width = "300px">

Panel1: Here is some static content...
<P>

</ASP: Panel>

<P>

Generate labels:
<Asp: dropdownlist id = dropdown1 runat = "server">
<Asp: listitem value = "0"> 0 </ASP: listitem>
<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: dropdownlist>

<Br>

Generate textboxes:
<Asp: dropdownlist id = dropdown2 runat = "server">
<Asp: listitem value = "0"> 0 </ASP: listitem>
<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: dropdownlist>

<P>
<Asp: checkbox id = "check1" text = "Hide panel" runat = "server"/>

<P>
<Asp: button text = "Refresh panel" runat = "server"/>


</Form>

</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.