共用方式為


WizardStepCollection.Insert(Int32, WizardStepBase) 方法

定義

將指定的 WizardStepBase 衍生物件插入位於指定索引位置的集合。

public:
 void Insert(int index, System::Web::UI::WebControls::WizardStepBase ^ wizardStep);
public void Insert (int index, System.Web.UI.WebControls.WizardStepBase wizardStep);
member this.Insert : int * System.Web.UI.WebControls.WizardStepBase -> unit
Public Sub Insert (index As Integer, wizardStep As WizardStepBase)

參數

index
Int32

要插入 WizardStepBase 衍生物件的索引位置。

wizardStep
WizardStepBase

要插入至 WizardStepBase 集合的 WizardStepCollection 衍生物件。

範例

下列程式代碼範例示範如何以程序設計方式建立 Wizard 控件,並使用 Insert 方法將衍生物件加入 WizardStepBase集合 WizardSteps 中。 請注意,在範例中, WizardSteps 控件的 Wizard 屬性是 類別 WizardStepCollection 的實例。

<%@ 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">

  // Programmatically create a Wizard control and dynamically
  // add WizardStep objects to it.    
  
  void Page_Load(object sender, EventArgs e) 
  {
    Wizard WizardControl = new Wizard();
      
    // Create some steps for the wizard and insert them
    // into the WizardStepCollection collection.
    for (int i = 0; i <= 5; i++)
    {
      WizardStepBase newStep = new WizardStep();
      newStep.ID = "Step" + (i + 1).ToString();
      WizardControl.WizardSteps.Insert(0, newStep);
    }

    WizardControl.ActiveStepIndex = 0;
    WizardControl.DisplaySideBar = true;
    
    // Display the wizard on the page.
    PlaceHolder1.Controls.Add(WizardControl);
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>WizardStepCollection Insert Example</title>
</head>
<body>
    <form id="Form1" runat="server">
      <h3>WizardStepCollection Insert Example</h3>
      <asp:PlaceHolder id="PlaceHolder1" 
        runat="server" />
    </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">

  ' Programmatically create a Wizard control and dynamically
  ' add WizardStep objects to it.    
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    Dim WizardControl As Wizard = New Wizard()
      
    ' Create some steps for the wizard and insert them
    ' into the WizardStepCollection collection.
    For i As Integer = 0 To 5
      Dim newStep As WizardStepBase = New WizardStep()
      newStep.ID = "Step" + (i + 1).ToString()
      WizardControl.WizardSteps.Insert(0, newStep)
    Next

    WizardControl.ActiveStepIndex = 0
    WizardControl.DisplaySideBar = True
    
    ' Display the wizard on the page.
    PlaceHolder1.Controls.Add(WizardControl)
  
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>WizardStepCollection Insert Example</title>
</head>
<body>
    <form id="Form1" runat="server">
      <h3>WizardStepCollection Insert Example</h3>
      <asp:PlaceHolder id="PlaceHolder1" 
        runat="server" />
    </form>
  </body>
</html>

備註

Insert方法會將WizardStepBase衍生物件加入集合中指定的索引位置。

或者,您可以使用 AddAt 方法,將 WizardStepBase衍生物件加入至集合。 若要將 WizardStepBase衍生物件新增至集合結尾 WizardStepCollection ,請使用 Add 方法。

注意

Insert方法和方法AddAt基本上會執行相同的函式。 Insert呼叫 方法時,它只會將 和 index 參數傳遞wizardStepAddAt 方法。

適用於

另請參閱