更新:2007 年 11 月
表示當做其他控制項的容器 (Container) 的控制項。
命名空間:
System.Web.UI.WebControls 組件:
System.Web (在 System.Web.dll 中)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Panel _
Inherits WebControl
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Panel : WebControl
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Panel : public WebControl
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Panel extends WebControl
public class Panel extends WebControl
Panel 控制項是其他控制項的容器。當您想要以程式設計方式產生控制項、隱藏/顯示控制項群組,或是當地語系化控制項群組時,會特別有用。
Direction 屬性可用來當地語系化 Panel 控制項的內容,以便顯示由右至左書寫的語言文字,例如阿拉伯文或希伯來文。
Panel 控制項提供多項屬性,可讓您自訂行為以及內容的顯示方式。請使用 BackImageUrl 屬性來顯示 Panel 控制項的自訂影像。請使用 ScrollBars 屬性,指定控制項的捲軸。
下列範例說明使用 Panel 控制項以程式設計的方式產生控制項和隱藏/顯示控制項群組。
注意事項: |
|---|
下列程式碼範例使用單一檔案程式碼模型,若直接複製到程式碼後置檔案,可能無法正確運作。這個程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。如需 Web Form 程式碼模型的詳細資訊,請參閱 ASP.NET Web 網頁程式碼模型。 |
<%@ 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>
<%@ 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>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.WebControl
System.Web.UI.WebControls..::.Panel
System.Web.UI.WebControls.WebParts..::.Part
這個型別的任何 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
參考
其他資源