ASP.NET - Multiview

MultiViews is a feature that allows you to define multiple views for a single page, each with its own content and layout. This feature can be useful when you want to display different content to different users based on their preferences or roles.

MultiViews are typically used to implement a "tabbed" interface, where users can switch between different views of the same data. Each view is associated with a separate user interface control, such as a button or a hyperlink, that users can click to switch between views.

Properties:

  • ActiveViewIndex: Gets or sets the index of the active view in the MultiView control.
  • Views: Gets a collection of View controls that are defined for the MultiView control.

Methods:

GetActiveView(): Returns the active View control in the MultiView control.

SetActiveView(View): Sets the specified View control as the active view in the MultiView control.

SwitchViews(View, View): Switches the active view from one View control to another.

Events:

ActiveViewChanged: Occurs when the active view in the MultiView control is changed.

 

Example 1: Tabbed interface

 

This example shows how to create a simple tabbed interface using the MultiView control. The user can switch between two views by clicking on the corresponding tab.

 

   

       

Tab 1

       

Contents of tab 1

   

   

       

Tab 2

       

Contents of tab 2

   

 

 

 

 

 

In the code-behind file, you can handle the button clicks to switch between views:

 

protected void btnTab1_Click(object sender, EventArgs e)

{

    mvTabs.SetActiveView(viewTab1);

}

 

protected void btnTab2_Click(object sender, EventArgs e)

{

    mvTabs.SetActiveView(viewTab2);

}

 

Example 2: MultiView control with a GridView and paging

 

This example demonstrates a more complex MultiView control that contains a GridView control and implements paging using multiple views. The first view contains the GridView control and the second view contains a "next" button.

 

   

       

           

               

               

           

       

       

       

   

   

       

   

 

In the code-behind file, you would handle the click event for the "next" button to switch to the second view and update the GridView control with the next page of data:

 

 

protected void btnNext_Click(object sender, EventArgs e)

{

    // Switch to the "next" view

    mvGrid.SetActiveView(viewNext);

    

    // Calculate the next page index

    int pageIndex = gridExample.PageIndex + 1;

    

    // Set the page index for the GridView control

    gridExample.PageIndex = pageIndex;

    

    // Rebind the GridView control with the updated data

}