Executing a Stored Procedure using SqlDataSource Control
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Executing a Stored Procedure using SqlDataSource Control</title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="categoriesSource" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:AdventureWorks %>" SelectCommand="GetProductSubCategories" SelectCommandType="StoredProcedure"> </asp:SqlDataSource> Categories: <asp:DropDownList runat="server" DataSourceID="categoriesSource" DataValueField="ProductSubcategoryID" DataTextField="Name" AutoPostBack="true" ID="lstCategories" /> <asp:SqlDataSource ID="productsSource" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:AdventureWorks %>" SelectCommand="GetProductsByCategoryID" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:ControlParameter ControlID="lstCategories" Name="ProductSubcategoryID" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> <asp:GridView runat="server" DataSourceID="productsSource" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White" /> </div> </form> </body> </html>