共用方式為


SqlDataSourceFilteringEventArgs.ParameterValues 屬性

定義

取得 IOrderedDictionary 物件,其可提供對 Parameter 類別之 SqlDataSource 物件的存取。

public:
 property System::Collections::Specialized::IOrderedDictionary ^ ParameterValues { System::Collections::Specialized::IOrderedDictionary ^ get(); };
public System.Collections.Specialized.IOrderedDictionary ParameterValues { get; }
member this.ParameterValues : System.Collections.Specialized.IOrderedDictionary
Public ReadOnly Property ParameterValues As IOrderedDictionary

屬性值

IOrderedDictionary 物件的 Parameter

範例

下列程式碼範例示範如何從 Northwind 資料庫擷取資料,並使用 和 FilterParameters 進行篩選 FilterExpressionFilterExpression每當執行 方法以擷取資料時, Select 就會套用 的 SqlDataSource 。 在此範例中 FilterExpression ,包含篩選參數的預留位置,包含在集合中 FilterParametersFiltering在 事件中,篩選參數會顯示在 控制項中 Label

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

    //Protected Sub SqlDataSource1_Filtering(ByVal sender As Object, _
    //    ByVal e As System.Web.UI.WebControls.SqlDataSourceFilteringEventArgs)
    //    Label1.Text = e.ParameterValues(0).ToString()
    //End Sub


    protected void SqlDataSource1_Filtering(object sender, SqlDataSourceFilteringEventArgs e)
    {
        Label1.Text = e.ParameterValues[0].ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="FORM1" runat="server">

            <p>Show all employees with the following title:
            <asp:DropDownList
                id="DropDownList1"
                runat="server"
                AutoPostBack="True">
                <asp:ListItem>Sales Representative</asp:ListItem>
                <asp:ListItem>Sales Manager</asp:ListItem>
                <asp:ListItem>Vice President, Sales</asp:ListItem>
            </asp:DropDownList></p>

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
                FilterExpression="Title='{0}'" OnFiltering="SqlDataSource1_Filtering">
                <FilterParameters>
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
                </FilterParameters>
            </asp:SqlDataSource><br />

            <asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </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">

    Protected Sub SqlDataSource1_Filtering(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.SqlDataSourceFilteringEventArgs)
        Label1.Text = e.ParameterValues(0).ToString()
    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">

            <p>Show all employees with the following title:
            <asp:DropDownList
                id="DropDownList1"
                runat="server"
                AutoPostBack="True">
                <asp:ListItem>Sales Representative</asp:ListItem>
                <asp:ListItem>Sales Manager</asp:ListItem>
                <asp:ListItem>Vice President, Sales</asp:ListItem>
            </asp:DropDownList></p>

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
                FilterExpression="Title='{0}'" OnFiltering="SqlDataSource1_Filtering">
                <FilterParameters>
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
                </FilterParameters>
            </asp:SqlDataSource><br />

            <asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </form>
    </body>
</html>

備註

類別 SqlDataSourceFilteringEventArgs 是用來將資料傳遞至 FilteringSqlDataSource 事件處理常式。 屬性 ParameterValues 會先存取篩選參數值,再執行篩選作業。

重要

您應該驗證您從用戶端收到的任何篩選參數值,並在參數無效時取消選取作業。 執行時間只會將參數值取代為篩選運算式,並將其套用至 select 方法的結果。 遭入侵的值可能會以顯示比用戶端可見更多資料列的方式來改變篩選運算式。 如果您使用 FilterExpression 屬性做為安全性量值來限制傳回的專案數,則必須在篩選發生之前驗證參數值。

適用於

另請參閱