SqlDataSourceFilteringEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説SqlDataSourceFilteringEventArgs クラスは、データを SqlDataSource コントロールの Filtering イベント ハンドラに渡す場合に使用されます。ParameterValues プロパティは、フィルタ操作を実行する前に、フィルタ パラメータ値へのアクセスを提供します。ObjectDataSourceFilteringEventArgs の Cancel プロパティを true に設定すると、Select メソッドをキャンセルできます。DataSourceMode プロパティの値が DataSet に設定されている場合、フィルタ処理がサポートされます。
使用例Northwind データベースからデータを取得し、FilterExpression と FilterParameters を使用してフィルタ処理する方法を次のコード例に示します。Select メソッドを実行してデータを取得するときは常に、SqlDataSource の FilterExpression が適用されます。この例では、FilterExpression に、FilterParameters コレクションに格納されているフィルタ パラメータのプレースホルダが格納されています。Filtering イベントで、フィルタ パラメータが Label コントロールに表示されます。
<%@ 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> <BODY> <FORM 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> <p><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="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> <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> <p><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>
継承階層System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.SqlDataSourceFilteringEventArgs
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照- SqlDataSourceFilteringEventArgs クラスのページへのリンク