MultiView.ActiveViewIndex Vlastnost

Definice

Získá nebo nastaví index aktivního View ovládacího prvku v MultiView rámci ovládacího prvku.

public:
 virtual property int ActiveViewIndex { int get(); void set(int value); };
public virtual int ActiveViewIndex { get; set; }
member this.ActiveViewIndex : int with get, set
Public Overridable Property ActiveViewIndex As Integer

Hodnota vlastnosti

Int32

Index aktivního View ovládacího prvku založený na nule v MultiView rámci ovládacího prvku. Výchozí hodnota je -1, což znamená, že žádné zobrazení není nastaveno jako aktivní.

Výjimky

Zadaný index byl nastaven na hodnotu menší než -1 nebo větší než nebo rovno počtu položek v seznamu.

Příklady

Následující příklad kódu ukazuje, jak pomocí MultiView ovládacího prvku vytvořit základní průzkum. Každý View ovládací prvek je samostatná otázka průzkumu. Když uživatel klikne na tlačítko Předchozí na libovolné stránce, ActiveViewIndex vlastnost se sníží a přejde na předchozí View ovládací prvek. Když uživatel klikne na tlačítko Další na libovolné stránce, ActiveViewIndex vlastnost se zvýší a přejde na další View ovládací prvek.

Poznámka

Následující ukázka kódu používá model kódu s jedním souborem a nemusí správně fungovat, pokud se zkopíruje přímo do souboru s kódem. Tento ukázkový kód se musí zkopírovat do prázdného textového souboru s příponou .aspx. Další informace o modelu kódu Web Forms najdete v tématu ASP.NET Web Forms Model kódu stránky.

<%@ Page Language="C#" %>

<!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>MultiView ActiveViewIndex Example</title>
<script runat="server">

  protected void NextButton_Command(object sender, EventArgs e)
  {
    // Determine which button was clicked
    // and set the ActiveViewIndex property to
    // the view selected by the user.
    if (DevPollMultiView.ActiveViewIndex > -1 & DevPollMultiView.ActiveViewIndex < 3)
    {
      // Increment the ActiveViewIndex property 
      // by one to advance to the next view.
      DevPollMultiView.ActiveViewIndex += 1;
    }
    else if (DevPollMultiView.ActiveViewIndex == 3)
    {
      // This is the final view.
      // The user wants to save the survey results.
      // Insert code here to save survey results.
      // Disable the navigation buttons.
      Page4Save.Enabled = false;
      Page4Restart.Enabled = false;
    }
    else
    {
      throw new Exception("An error occurred.");
    }
  }

  protected void BackButton_Command(object sender, EventArgs e)
  {
    if (DevPollMultiView.ActiveViewIndex > 0 & DevPollMultiView.ActiveViewIndex <= 2)
    {
      // Decrement the ActiveViewIndex property
      // by one to return to the previous view.
      DevPollMultiView.ActiveViewIndex -= 1;
    }
    else if (DevPollMultiView.ActiveViewIndex == 3)
    {
      // This is the final view.
      // The user wants to restart the survey.
      // Return to the first view.
      DevPollMultiView.ActiveViewIndex = 0;
    }
    else
    {
      throw new Exception("An error occurred.");
    }
  }

  </script>

</head>
<body>
    <form id="Form1" runat="Server">
        
        <h3>MultiView ActiveViewIndex Example</h3>
        
        <asp:Panel id="Page1ViewPanel" 
            Width="330px" 
            Height="150px"
            HorizontalAlign="Left"
            Font-size="12" 
            BackColor="#C0C0FF" 
            BorderColor="#404040"
            BorderStyle="Double"                     
            runat="Server">  

            <asp:MultiView id="DevPollMultiView"
                ActiveViewIndex="0"
                runat="Server">

                <asp:View id="Page1" 
                    runat="Server">   

                    <asp:Label id="Page1Label" 
                        Font-bold="true"                         
                        Text="What kind of applications do you develop?"
                        runat="Server"
                        AssociatedControlID="Page1">
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page1Radio1"
                         Text="Web Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                    </asp:RadioButton><br />

                    <asp:RadioButton id="Page1Radio2"
                         Text="Windows Forms Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                     </asp:RadioButton><br /><br /><br />                                       
                     
                    <asp:Button id="Page1Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button>     
                          
                </asp:View>

                <asp:View id="Page2" 
                    runat="Server">

                    <asp:Label id="Page2Label" 
                        Font-bold="true"                        
                        Text="How long have you been a developer?"
                        runat="Server"
                        AssociatedControlID="Page2">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page2Radio1"
                         Text="Less than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page2Radio2"
                         Text="More than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br /><br />

                    <asp:Button id="Page2Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button> 

                    <asp:Button id="Page2Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 
                
                </asp:View>

                <asp:View id="Page3" 
                    runat="Server">

                    <asp:Label id="Page3Label1" 
                        Font-bold="true"                        
                        Text= "What is your primary programming language?"                        
                        runat="Server"
                        AssociatedControlID="Page3">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page3Radio1"
                         Text="Visual Basic .NET" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio2"
                         Text="C#" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio3"
                         Text="C++" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br />

                     <asp:Button id="Page3Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 

                    <asp:Button id="Page3Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button><br />
                    
                </asp:View>     
            
                <asp:View id="Page4"
                    runat="Server">
                    
                    <asp:Label id="Label1"
                        Font-bold="true"                                           
                        Text = "Thank you for taking the survey."
                        runat="Server"
                        AssociatedControlID="Page4">
                    </asp:Label>
                    
                    <br /><br /><br /><br /><br /><br />              
                   
                    <asp:Button id="Page4Save"
                        Text = "Save Responses"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="110"
                        runat="Server">
                    </asp:Button>
                
                    <asp:Button id="Page4Restart"
                        Text = "Retake Survey"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="110"
                        runat= "Server">
                    </asp:Button>                    
                    
                </asp:View>  
       
            </asp:MultiView>
        
        </asp:Panel> 

    </form>
</body>
</html>
<%@ 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>MultiView ActiveViewIndex Example</title>
<script runat="server">

        Sub NextButton_Command(sender As Object, e As System.EventArgs)
            ' Determine which button was clicked
            ' and set the ActiveViewIndex property to
            ' the view selected by the user.
            If (DevPollMultiView.ActiveViewIndex > -1) AND DevPollMultiView.ActiveViewIndex < 3 Then
                ' Increment the ActiveViewIndex property 
                ' by one to advance to the next view.
                DevPollMultiView.ActiveViewIndex += 1
            ElseIf DevPollMultiView.ActiveViewIndex = 3 Then
                ' This is the final view.
                ' The user wants to save the survey results.
                ' Insert code here to save survey results.
                ' Disable the navigation buttons.
                Page4Save.Enabled = False
                Page4Restart.Enabled = False
            Else
                Throw New Exception("An error occurred.")

            End If

        End Sub

        Sub BackButton_Command(ByVal sender As Object, ByVal e As System.EventArgs)
            If (DevPollMultiView.ActiveViewIndex > 0) And DevPollMultiView.ActiveViewIndex <= 2 Then
                ' Decrement the ActiveViewIndex property
                ' by one to return to the previous view.
                DevPollMultiView.ActiveViewIndex -= 1
            ElseIf DevPollMultiView.ActiveViewIndex = 3 Then
                ' This is the final view.
                ' The user wants to restart the survey.
                ' Return to the first view.
                DevPollMultiView.ActiveViewIndex = 0
            Else
                Throw New Exception("An error occurred.")

            End If

        End Sub

</script>

</head>
<body>
    <form id="Form1" runat="Server">
        
        <h3>MultiView ActiveViewIndex Example</h3>
        
        <asp:Panel id="Page1ViewPanel" 
            Width="330px" 
            Height="150px"
            HorizontalAlign ="Left"
            Font-size="12" 
            BackColor="#C0C0FF" 
            BorderColor="#404040"
            BorderStyle="Double"                     
            runat="Server">  

            <asp:MultiView id="DevPollMultiView"
                ActiveViewIndex="0"
                runat="Server">

                <asp:View id="Page1" 
                    runat="Server">   

                    <asp:Label id="Page1Label" 
                        Font-bold="true"                         
                        Text="What kind of applications do you develop?"
                        runat="Server"
                        AssociatedControlID="Page1">
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page1Radio1"
                         Text="Web Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                    </asp:RadioButton><br />

                    <asp:RadioButton id="Page1Radio2"
                         Text="Windows Forms Applications" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="server" >
                     </asp:RadioButton><br /><br /><br />                                       
                     
                    <asp:Button id="Page1Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button>     
                          
                </asp:View>

                <asp:View id="Page2" 
                    runat="Server">

                    <asp:Label id="Page2Label" 
                        Font-bold="true"                        
                        Text="How long have you been a developer?"
                        runat="Server"
                        AssociatedControlID="Page2">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page2Radio1"
                         Text="Less than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page2Radio2"
                         Text="More than five years" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br /><br />

                    <asp:Button id="Page2Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat= "Server">
                    </asp:Button> 

                    <asp:Button id="Page2Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 
                
                </asp:View>

                <asp:View id="Page3" 
                    runat="Server">

                    <asp:Label id="Page3Label1" 
                        Font-bold="true"                        
                        Text= "What is your primary programming language?"                        
                        runat="Server"
                        AssociatedControlID="Page3">                    
                    </asp:Label><br /><br />

                    <asp:RadioButton id="Page3Radio1"
                         Text="Visual Basic .NET" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio2"
                         Text="C#" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br />

                    <asp:RadioButton id="Page3Radio3"
                         Text="C++" 
                         Checked="False" 
                         GroupName="RadioGroup1" 
                         runat="Server">
                     </asp:RadioButton><br /><br />

                     <asp:Button id="Page3Back"
                        Text = "Previous"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button> 

                    <asp:Button id="Page3Next"
                        Text = "Next"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="70"
                        runat="Server">
                    </asp:Button><br />
                    
                </asp:View>     
            
                <asp:View id="Page4"
                    runat="Server">
                    
                    <asp:Label id="Label1"
                        Font-bold="true"                                           
                        Text = "Thank you for taking the survey."
                        runat="Server"
                        AssociatedControlID="Page4">
                    </asp:Label>
                    
                    <br /><br /><br /><br /><br /><br />              
                   
                    <asp:Button id="Page4Save"
                        Text = "Save Responses"
                        OnClick="NextButton_Command"
                        Height="25"
                        Width="110"
                        runat="Server">
                    </asp:Button>
                
                    <asp:Button id="Page4Restart"
                        Text = "Retake Survey"
                        OnClick="BackButton_Command"
                        Height="25"
                        Width="110"
                        runat= "Server">
                    </asp:Button>                    
                    
                </asp:View>  
       
            </asp:MultiView>
        
        </asp:Panel> 

    </form>
</body>
</html>

Poznámky

ActiveViewIndex Vlastnost slouží k nastavení View ovládacího prvku v ovládacím MultiView prvku jako aktivního zobrazení. Tuto vlastnost můžete použít také k vrácení indexu View ovládacího prvku, který je aktuálně nastavený jako aktivní zobrazení. Index View ovládacího prvku je určen pořadím, ve kterém je deklarován v MultiView rámci ovládacího prvku. Například první View ovládací prvek deklarovaný v MultiView rámci ovládacího prvku má index 0.

V rámci ovládacího prvku lze definovat pouze jeden View ovládací prvek najednou jako aktivní MultiView . Ovládací View prvek, který je nastavený na ActiveViewIndex vlastnost, se vykreslí klientovi. ActiveViewIndex Pokud je vlastnost nastavena na View hodnotu, která v ovládacím MultiView prvku neexistuje, ArgumentOutOfRangeException vyvolá se za běhu. Pokud je vlastnost prázdná, MultiView ovládací prvek nevykreslí klientovi žádný obsah.

Vlastnost můžete nastavit ActiveViewIndex deklarativním způsobem v době vývoje nebo programově v době běhu. ActiveViewIndex Nastavení vlastnosti deklarativní při definování MultiView ovládacího prvku způsobíView, že ovládací prvek, který je nastaven jako aktivní zobrazení vykreslovat klientovi při prvním zavolání MultiView ovládacího prvku. ActiveViewIndex Nastavení vlastnosti programově umožňuje aplikaci určit, který View ovládací prvek se má vykreslit klientovi za běhu na základě kritérií, jako je identita uživatele nebo jejich předvolby.

Alternativně můžete pomocí SetActiveView metod GetActiveView nastavit nebo získat aktivní zobrazení v ovládacím MultiView prvku.

Platí pro

Viz také