Wizard.ActiveStepIndex 屬性

定義

取得或設定目前 WizardStepBase 物件的索引。

public:
 virtual property int ActiveStepIndex { int get(); void set(int value); };
[System.Web.UI.Themeable(false)]
public virtual int ActiveStepIndex { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.ActiveStepIndex : int with get, set
Public Overridable Property ActiveStepIndex As Integer

屬性值

Int32

目前顯示在 WizardStepBase 控制項中的 Wizard 物件索引。

屬性

例外狀況

選取的值大於 WizardSteps 集合中定義的精靈步驟數目。

範例

下列程式碼範例示範如何使用 ActiveStepIndex 屬性來設定 ActiveStep 控制項的 Wizard 屬性。 如果 的值為 CheckBox1.Checked true ,則 ActiveStep 屬性會設定為 Wizard1.Step3ActiveStep 否則屬性會設定為 Wizard1.Step2

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

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

<script runat="server">

  void OnActiveStepChanged(object sender, EventArgs e)
  {
    // If the ActiveStep is changing to Step2, check to see whether the 
    // CheckBox1 CheckBox is selected.  If it is, skip to the Step2 step.
    if (Wizard1.ActiveStepIndex == Wizard1.WizardSteps.IndexOf(this.WizardStep2))
    {
      if (this.CheckBox1.Checked)
      {
        Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(this.WizardStep3);
      }
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
      <form id="form1" runat="server">
        <asp:Wizard id="Wizard1" 
          runat="server"
          OnActiveStepChanged="OnActiveStepChanged">
          <WizardSteps>
            <asp:WizardStep id="WizardStep1" 
              title="Step 1" 
              runat="server">
              <asp:CheckBox id="CheckBox1" 
                runat="Server" 
                text="Select this check box to skip Step 2." />
                You are currently on Step 1.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep2" 
              title="Step 2" 
              runat="server">
              You are currently on Step 2.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep3" 
              runat="server" 
              title="Step 3">
              You are currently on Step 3.
            </asp:WizardStep>
          </WizardSteps>
          <HeaderTemplate>
            <b>ActiveStepIndex Example</b>
          </HeaderTemplate>
        </asp:Wizard>
      </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">

<script runat="server">

  Sub OnActiveStepChanged(ByVal sender As Object, ByVal e As EventArgs)
    ' If the ActiveStep is changing to Step2, check to see whether the 
    ' CheckBox1 CheckBox is selected.  If it is, skip to the Step3 step. 
    If (Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(Me.WizardStep2)) Then
      If (Me.CheckBox1.Checked) Then
        Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(Me.WizardStep3)
      End If
    End If
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
      <form id="form1" runat="server">
        <asp:Wizard id="Wizard1" 
          runat="server"
          OnActiveStepChanged="OnActiveStepChanged">
          <WizardSteps>
            <asp:WizardStep id="WizardStep1" 
              title="Step 1" 
              runat="server">
              <asp:CheckBox id="CheckBox1" 
                runat="Server" 
                text="Select this check box to skip Step 2." />
                You are currently on Step 1.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep2" 
              title="Step 2" 
              runat="server">
              You are currently on Step 2.
            </asp:WizardStep>
            <asp:WizardStep id="WizardStep3" 
              runat="server" 
              title="Step 3">
              You are currently on Step 3.
            </asp:WizardStep>
          </WizardSteps>
          <HeaderTemplate>
            <b>ActiveStepIndex Example</b>
          </HeaderTemplate>
        </asp:Wizard>
      </form>
  </body>
</html>

備註

屬性 ActiveStepIndex 會提供目前顯示在 控制項中之 物件的以零起始的 Wizard 索引 WizardStepBase 。 您可以透過程式設計方式設定 ActiveStepIndex 屬性,以控制在執行時間向使用者顯示的步驟。

注意

如果您使用 Microsoft Visual Studio 2005,請注意,會 ActiveStepIndex 保存在 [來源] 檢視中。 如果您按一下側邊欄按鈕,然後在 [設計] 檢視中變更 WizardSteps 屬性,然後執行頁面,則可能不會顯示控制項的第一個步驟 Wizard ,因為 ActiveStepIndex 可能會指向不同的步驟。

如果您將 的值 ActiveStepIndex 設定為 -1 以支援預設沒有步驟的精靈,就會發生下列行為:

  • 如果您以宣告方式將 設定 ActiveStepIndex 為 -1,或將它設定為 -1 做為預設值,控制項一律會嘗試轉譯精靈中的第一個步驟。

  • 如果您以程式設計方式將 設定 ActiveStepIndex 為 -1,控制項將不會轉譯。

這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttributeASP.NET 主題和外觀

適用於

另請參閱