MultiView control in ASP.NET using VB.NET

In this article we will learn how to use multiview and view control in ASP.NET.
  • 1292

This article shows multiview control in ASP.NET.

MultiView Control

The MultiView control represents a control that acts as a container for groups of View controls.. It creates a set of views and one view is visible at a time. Use View control to create views inside the MutliView control. Add the View controls into a MultiView control.

For example:

Drop one multiview control, Three view control, one textbox control and one calendar control and one textbox and button control and one dropdownlist control from the toolbox on the form. form looks like this:

mv1.gif
 

Figure 1.

Now click on the source button of the above figure1 and add the following code.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        MultiView1.ActiveViewIndex = DropDownList1.SelectedValue

    End Sub

   

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>Untitled Page</title>

</head>

<body>

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

        <div>

            <h3>

                <font face="Verdana">MultiView with 3 Views</font>

            </h3>

            <asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

                runat="server" AutoPostBack="True">

                <asp:ListItem Value="0">View 1</asp:ListItem>

                <asp:ListItem Value="1">View 2</asp:ListItem>

                <asp:ListItem Value="2">View 3</asp:ListItem>

            </asp:DropDownList><br />

            <hr />

            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">

                <asp:View ID="View1" runat="server">

                    Now showing View #1<br />

                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><strong> </strong>

                    <asp:Button ID="Button1" runat="server" Text="Button" /></asp:View>

                <asp:View ID="View2" runat="server">

                    Now showing View #2<br />

                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.asp.net">HyperLink</asp:HyperLink>

                    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="http://www.asp.net">HyperLink</asp:HyperLink></asp:View>

                <asp:View ID="View3" runat="server">

                    Now showing View #3<br />

                    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>

                </asp:View>

            </asp:MultiView></div>

    </form>

</body>

</html>

Now save and run the application.

mv2.gif
 

Figure 2.

Now click on the DropDownList and select the view1,view2,view3. Suppose we select view1 from DropDownList.

mv3.gif
 

Figure 3.

Again click on the DropDownList and select the view1,view2,view3. Suppose we select view2 from DropDownList.

mv4.gif
 

Figure 4.

Now Again click on the DropDownList and select the view1,view2,view3. Suppose we select view3 from DropDownList.

mv5.gif
 

Figure 5.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.