ParameterCollection.Insert(Int32, Parameter) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的 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)
參數
例外狀況
範例
下列程式碼範例示範如何使用 Insert 方法,將 物件新增 Parameter 至 ParameterCollection 特定位置的集合。 在此範例中,會將數 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>