共用方式為


ParameterCollection.Insert(Int32, Parameter) 方法

定義

將指定的 Parameter 物件插入 ParameterCollection 集合中的指定索引處。

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

參數

index
Int32

以零為基底的索引,這是插入 Parameter 之處。

parameter
Parameter

要插入的 Parameter

例外狀況

index 小於零。

-或-

index 大於 Count

範例

下列程式碼範例示範如何使用 Insert 方法,將 物件新增 ParameterParameterCollection 特定位置的集合。 在此範例中,會將數 QueryStringParameter 個物件加入至集合中,一個 SelectParametersQueryStringParameter 物件會插入集合中,並在頁面載入時列印集合的順序。

<%@page Language="C#" %>
<SCRIPT runat="server">
private void Page_Load(object sender, EventArgs e) {

    SqlDataSource aSqlDataSource = new SqlDataSource();

    // Security Note: The SqlDataSource uses a QueryStringParameter,
    // Security Note: which does not perform validation of input from the client.


    QueryStringParameter qs1 =
        new QueryStringParameter("QueryStringParam1","requestfield1");
    aSqlDataSource.SelectParameters.Add(qs1);

    QueryStringParameter qs3 =
        new QueryStringParameter("QueryStringParam3","requestfield3");
    aSqlDataSource.SelectParameters.Add(qs3);

    // Insert
    aSqlDataSource.SelectParameters.Insert(1, new QueryStringParameter("QueryStringParam2", "requestField2") );

    // Iterate through the ParameterCollection and print out the
    // names of the Parameters contained by it.
    foreach (Parameter aParameter in aSqlDataSource.SelectParameters) {
        Response.Write(aParameter.Name + "<BR>");
    }
}
</SCRIPT>
<%@page Language="VB" %>
<SCRIPT runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

    Dim aSqlDataSource As New SqlDataSource()

   ' Security Note: The SqlDataSource uses a QueryStringParameter,
   ' Security Note: which does not perform validation of input from the client.

    Dim qs1 As New QueryStringParameter("QueryStringParam1","requestfield1")
    aSqlDataSource.SelectParameters.Add(qs1)

    Dim qs3 As New QueryStringParameter("QueryStringParam3","requestfield3")
    aSqlDataSource.SelectParameters.Add(qs3)

    Dim qs2 As New QueryStringParameter("QueryStringParam2","requestField2")
    ' Insert
    aSqlDataSource.SelectParameters.Insert(1, qs2)

    ' Iterate through the ParameterCollection and print out the
    ' names of the Parameters contained by it.
    Dim aParameter As Parameter
    For Each aParameter in aSqlDataSource.SelectParameters
        Response.Write(aParameter.Name & "<BR>")
    Next
End Sub ' Page_Load
</SCRIPT>

適用於

另請參閱