How to use ControlParameter in asp.net c#

ControlParameter
ControlParameterExample.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>asp.net ControlParameter example: how to use ControlParameter</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Teal">ControlParameter Example</h2>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT CategoryID, CategoryName FROM Categories">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID=@CategoryID">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="CategoryID" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Label ID="Label1" runat="server" Text="Category" AssociatedControlID="DropDownList1" ForeColor="Green"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="true" >
        </asp:DropDownList>
        <br /><br />
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource2" ForeColor="SlateGray" BackColor="Snow" BorderColor="HotPink">
        </asp:GridView>
    </div>
    </form>
</body>
</html>
More asp.net examples