Views Property
Collapse the table of content
Expand the table of content

MultiView.Views Property


Gets the collection of View controls in the MultiView control.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual ViewCollection Views { get; }

Property Value

Type: System.Web.UI.WebControls.ViewCollection

A ViewCollection that represents a collection of View controls within a MultiView control. The default is null.

Use this property to programmatically manage the View controls in a MultiView control.

The following example demonstrates how to programmatically add View controls to a MultiView control. After each View control is created, the MultiView.Views.Add() syntax is used to add the View control to the ViewCollection collection of the MultiView control.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
    <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.

                ' Set myView as the active view.

                ' The Panel control was initially set to not visible.
                ' Set it to visible to add styles to the myView.

                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.

            Return myView
        End Function



    <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"
            <asp:ListItem Value="0">View1</asp:ListItem>
            <asp:ListItem Value="1">View2</asp:ListItem>
        </asp:ListBox><br /><br />

        <hr /><br /> 

        <asp:Panel ID="Panel1"
            Visible = "False"

            <asp:MultiView ID="MultiView1"




.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft