MultiView.Views 屬性

定義

取得 View 控制項中 MultiView 控制項的集合。

public:
 virtual property System::Web::UI::WebControls::ViewCollection ^ Views { System::Web::UI::WebControls::ViewCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)]
public virtual System.Web.UI.WebControls.ViewCollection Views { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)>]
member this.Views : System.Web.UI.WebControls.ViewCollection
Public Overridable ReadOnly Property Views As ViewCollection

屬性值

ViewCollection,表示 View 控制項中 MultiView 控制項的集合。 預設為 null

屬性

範例

下列範例示範如何以程式設計方式將控制項 MultiView 加入 View 控制項。 建立每個 View 控制項之後, MultiView.Views.Add() 語法會用來將控制項新增 ViewViewCollection 控制項的 MultiView 集合。

注意

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

<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ViewCollection Class Example</title>
<script runat="server">

        Sub Index_Changed(ByVal Sender As Object, ByVal e As EventArgs)
            ' A MultiView was added to the page declaratively.
            ' Now add the View control programmatically.            
            
            If SelectViewListBox.SelectedIndex >= 0 Then
                ' The user selected a view.
                ' Determine which view the user selected.
            
                Dim viewName As String = SelectViewListBox.SelectedItem.Text
                Dim myView as New View

                ' Use a helper function to create the view.
                myView = CreateView(viewName, "This is " + viewName)

                ' Add myView to the ViewCollection of the MultiView1 control.
                MultiView1.Views.Add(myView)

                ' Set myView as the active view.
                MultiView1.SetActiveView(myView)

                ' The Panel control was initially set to not visible.
                ' Set it to visible to add styles to the myView.
                Panel1.Visible=True
          
            Else
                Throw New Exception("You did not select a valid view.")

            End If

        End Sub
        
        ' A function to programmatically create a View control.
        Private Function CreateView(ByVal viewId As String, ByVal viewDescription As String) As View
            ' Create a View control
            Dim myView As New View
            myView.ID = viewId
            
            ' Create a Label control.
            Dim Label1 As New Label

            ' Set the text property for the label.
            Label1.Text = viewDescription
            
            ' Add the label to the controls collection of the view.
            myView.Controls.Add(Label1)
            
            Return myView
        End Function

</script>
 
</head>
<body>

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

        <h3>ViewCollection Class Example</h3>

        <h4>Select a View to create and display in a MultiView control:</h4>
            
        <asp:ListBox ID="SelectViewListBox"
            AutoPostBack="True"
            Rows="1"
            SelectionMode="Single"
            OnSelectedIndexChanged="Index_Changed"
            runat="Server">
            <asp:ListItem Value="0">View1</asp:ListItem>
            <asp:ListItem Value="1">View2</asp:ListItem>
        </asp:ListBox><br /><br />
        
        <hr /><br /> 
        
        <asp:Panel ID="Panel1"
            Height="75px"
            Width="100px"
            Backcolor="Aqua"
            BorderStyle="Double" 
            Visible = "False"
            runat="Server"> 

            <asp:MultiView ID="MultiView1"
                runat="Server">
            </asp:MultiView>

        </asp:Panel>
    
    </form>
   
</body>
</html>

備註

使用這個屬性以程式設計方式管理 View 控制項中的 MultiView 控制項。

適用於

另請參閱