SqlDataSourceFilteringEventHandler 委托

定义

表示将处理 Filtering 控件的 SqlDataSource 事件的方法。

public delegate void SqlDataSourceFilteringEventHandler(System::Object ^ sender, SqlDataSourceFilteringEventArgs ^ e);
public delegate void SqlDataSourceFilteringEventHandler(object sender, SqlDataSourceFilteringEventArgs e);
type SqlDataSourceFilteringEventHandler = delegate of obj * SqlDataSourceFilteringEventArgs -> unit
Public Delegate Sub SqlDataSourceFilteringEventHandler(sender As Object, e As SqlDataSourceFilteringEventArgs)

参数

sender
Object

事件的源,即 SqlDataSource

示例

下面的代码示例演示如何从 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>

注解

当 属性设置为 值时 DataSourceModeDataSet 支持筛选。

创建 SqlDataSourceFilteringEventHandler 委托时,需要标识将要处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关如何处理事件的详细信息,请参阅 处理和引发事件

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅