FilterParametersExample.aspx
<%@ 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">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net SqlDataSource example: using FilterParameters, FilterExpression</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">FilterParameters Example</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ProductID, ProductName FROM Products"
>
</asp:SqlDataSource>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="ProductName"
DataValueField="ProductID"
AutoPostBack="true"
ForeColor="SeaGreen"
BackColor="DarkGreen"
>
</asp:DropDownList>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products"
FilterExpression="ProductID='{0}'"
>
<FilterParameters>
<asp:ControlParameter Name="ProductID" ControlID="DropDownList1" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<br /><br />
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource2"
HeaderStyle-BackColor="HotPink"
HeaderStyle-ForeColor="AntiqueWhite"
BorderColor="SaddleBrown"
ForeColor="SeaGreen"
>
</asp:GridView>
</div>
</form>
</body>
</html>
Filtering in GridView in C#.NET
ReplyDelete