按一下以給予評分及指教
MSDN
MSDN Library
.NET 開發
.NET Framework
Panel 類別

  開啟低頻寬檢視
本頁僅適用於
Microsoft Visual Studio 2008/.NET Framework 3.5

其他版本也適用於下列軟體:
.NET Framework 類別庫
Panel 類別

更新:2007 年 11 月

表示當做其他控制項的容器 (Container) 的控制項。

命名空間:  System.Web.UI.WebControls
組件:  System.Web (在 System.Web.dll 中)

Visual Basic (宣告)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Panel _
    Inherits WebControl
Visual Basic (使用方式)
Dim instance As Panel
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Panel : WebControl
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Panel : public WebControl
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Panel extends WebControl
JScript
public class Panel extends WebControl
ASP.NET
<asp:Panel />

Panel 控制項是其他控制項的容器。當您想要以程式設計方式產生控制項、隱藏/顯示控制項群組,或是當地語系化控制項群組時,會特別有用。

Direction 屬性可用來當地語系化 Panel 控制項的內容,以便顯示由右至左書寫的語言文字,例如阿拉伯文或希伯來文。

Panel 控制項提供多項屬性,可讓您自訂行為以及內容的顯示方式。請使用 BackImageUrl 屬性來顯示 Panel 控制項的自訂影像。請使用 ScrollBars 屬性,指定控制項的捲軸。

TopicLocation
HOW TO:以程式設計方式加入控制項至 ASP.NET Web 網頁建置 ASP .NET Web 應用程式
HOW TO:以程式設計方式加入控制項至 ASP.NET Web 網頁在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:在 ASP.NET Web 伺服器控制項上設定焦點建置 ASP .NET Web 應用程式
HOW TO:在 ASP.NET Web 伺服器控制項上設定焦點在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:將 Panel Web 伺服器控制項加入至 Web Form 網頁建置 ASP .NET Web 應用程式
HOW TO:將 Panel 控制項加入至 Web Form 網頁在 Visual Studio 中建立 ASP .NET Web 應用程式
HOW TO:將 Panel 控制項加入至 Web Form 網頁 (Visual Studio)在 Visual Studio 中建置 ASP .NET Web 應用程式
HOW TO:逐一查看控制項集合以尋找頁面上的 Web Form 控制項建置 ASP .NET Web 應用程式
HOW TO:逐一查看控制項集合以尋找頁面上的 Web Form 控制項在 Visual Studio 中建立 ASP .NET Web 應用程式
逐步解說:在 Visual Web Developer 中建立和使用 ASP.NET 主版頁面在 Visual Studio 中建置 ASP .NET Web 應用程式
逐步解說:在 Visual Web Developer 中建立和使用 ASP.NET 主版頁面使用 Visual Web Developer 建置應用程式
逐步解說:建立可及性 Web 應用程式在 Visual Studio 中建置 ASP .NET Web 應用程式
逐步解說:建立可及性 Web 應用程式使用 Visual Web Developer 建置應用程式
逐步解說:資料繫結至自訂的商務物件在 Visual Studio 中建置 ASP .NET Web 應用程式
逐步解說:資料繫結至自訂的商務物件在 Visual Studio 中建立 ASP .NET Web 應用程式

下列範例說明使用 Panel 控制項以程式設計的方式產生控制項和隱藏/顯示控制項群組。

注意事項:

下列程式碼範例使用單一檔案程式碼模型,若直接複製到程式碼後置檔案,可能無法正確運作。這個程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。如需 Web Form 程式碼模型的詳細資訊,請參閱 ASP.NET Web 網頁程式碼模型

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
 <head>
    <title>Panel Example</title>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)

        ' Show or Hide the Panel contents.
        If Check1.Checked Then
            Panel1.Visible = False
        Else
            Panel1.Visible = True
        End If

        ' Generate the Label controls.
        Dim numlabels As Integer = Int32.Parse(DropDown1.SelectedItem.Value)

        Dim i As Integer
        For i = 1 To numlabels
            Dim l As New Label()
            l.Text = "Label" + i.ToString()
            l.ID = "Label" + i.ToString()
            Panel1.Controls.Add(l)
            Panel1.Controls.Add(New LiteralControl("<br />"))
        Next i

        ' Generate the Textbox controls.
        Dim numtexts As Integer = Int32.Parse(DropDown2.SelectedItem.Value)

        For i = 1 To numtexts
            Dim t As New TextBox()
            t.Text = "TextBox" & i.ToString()
            t.ID = "TextBox" & i.ToString()
            Panel1.Controls.Add(t)
            Panel1.Controls.Add(New LiteralControl("<br />"))
        Next i
    End Sub

    </script>

 </head>
 <body>

    <h3>Panel Example</h3>

    <form id="form1" runat="server">

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

            Panel1: Here is some static content...
            <br />

       </asp:Panel>

       <br />

       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>

       <br />
       <asp:CheckBox id="Check1" Text="Hide Panel" runat="server"/>

       <br />
       <asp:Button Text="Refresh Panel" runat="server"/>


    </form>

 </body>
 </html>


C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
 <head>
    <title>Panel Example</title>
<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</h3>

    <form id="form1" runat="server">

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

            Panel1: Here is some static content...
            <br />

       </asp:Panel>

       <br />

       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>

       <br />
       <asp:CheckBox id="Check1" Text="Hide Panel" runat="server"/>

       <br />
       <asp:Button Text="Refresh Panel" runat="server"/>


    </form>

 </body>
 </html>


這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

.NET Framework

支援版本:3.5、3.0、2.0、1.1、1.0
社群內容   什麼是社群內容?
新增內容 RSS  註解
Processing
© 2009 Microsoft Corporation. 著作權所有,並保留一切權利。 使用規定  |  商標  |  隱私權聲明
Page view tracker