LinqDataSourceSelectEventArgs.WhereParameters 屬性

定義

取得用於建立 Where 子句的參數集合。Gets the collection of parameters that is used to create the Where clause.

public:
 property System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ WhereParameters { System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ get(); };
public System.Collections.Generic.IDictionary<string,object> WhereParameters { get; }
member this.WhereParameters : System.Collections.Generic.IDictionary<string, obj>
Public ReadOnly Property WhereParameters As IDictionary(Of String, Object)

屬性值

IDictionary<String,Object>

物件,包含 Where 子句的參數。An object that contains the parameters for the Where clause.

範例

下列範例顯示如何將參數加入至 WhereParameters 集合。The following example shows how to add a parameter to the WhereParameters collection. 加入的參數會將傳回的產品限制為只有屬性中值為 "自行車" 的產品 NameThe added parameter will limit the returned products to only those products with a value of "Bike" in the Name property. AutoGenerateWhereClause屬性設定為, true 讓參數自動包含在 Where 子句中。The AutoGenerateWhereClause property is set to true so that the parameter is automatically included in the Where clause.

<script runat="server">
    protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        e.WhereParameters.Add("Name", "Bike");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Example Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinqDataSource 
            ContextTypeName="ExampleDataContext" 
            TableName="Products" 
            AutoGenerateWhereClause="true" 
            OnSelecting="LinqDataSource_Selecting" 
            ID="LinqDataSource1" 
            runat="server">
        </asp:LinqDataSource>
        <asp:GridView 
            DataSourceID="LinqDataSource1" 
            ID="GridView1" 
            runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>
<script runat="server">
    Protected Sub LinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs)
        e.WhereParameters.Add("Name", "Bike")
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Example Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        
        <asp:LinqDataSource 
            ContextTypeName="ExampleDataContext" 
            TableName="Products" 
            AutoGenerateWhereClause="true" 
            OnSelecting="LinqDataSource_Selecting" 
            ID="LinqDataSource1" 
            runat="server">
        </asp:LinqDataSource>
        <asp:GridView 
            DataSourceID="LinqDataSource1" 
            ID="GridView1" 
            runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

備註

在事件的 WhereParameters 處理常式中,您可以使用屬性來存取 Where 子句的參數 SelectingYou use the WhereParameters property to access parameters for the Where clause in a handler for the Selecting event. 您可以藉由新增或移除此集合中的參數,來修改 Where 子句。You can modify the Where clause by adding or removing parameters from this collection. 根據預設, WhereParameters 物件的屬性會 LinqDataSourceSelectEventArgs 包含您加入至控制項之的任何參數 WhereParameters LinqDataSourceBy default, the WhereParameters property of the LinqDataSourceSelectEventArgs object contains any parameters that you added to the WhereParameters of the LinqDataSource control.

當您透過物件的集合加入參數時 WhereParameters LinqDataSourceSelectEventArgs ,您必須在屬性中包含參數的預留位置, Where 或將 AutoGenerateWhereClause 屬性設為 trueWhen you add parameters through the WhereParameters collection of the LinqDataSourceSelectEventArgs object, you must either include a placeholder for the parameter in the Where property or set the AutoGenerateWhereClause property to true. 例如,如果您在事件的事件處理常式中加入名為的參數 ProductName Selecting ,您必須將屬性設定 AutoGenerateWhereClause 為, true 或將 Where 屬性設為 ProductName=@ProductNameFor example, if you add a parameter named ProductName in the event handler for the Selecting event, you must either set the AutoGenerateWhereClause property to true or set the Where property to ProductName=@ProductName.

適用於

另請參閱