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.Step3;否则,该 ActiveStep 属性设置为 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 主题和外观

适用于

另请参阅