給你個例子CREATE PROCEDURE [dbo].[GetProductsByCategoryID] @ProductSubcategoryID int AS SELECT ProductID, Name, ProductNumber FROM Production.Product WHERE ProductSubcategoryID=@ProductSubcategoryID ORDER BY ProductID Categories: <asp:DropDownList ID="lstCategories" DataSourceID="categoriesSource" runat="server" DataValueField="ProductSubcategoryID" DataTextField="Name" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:WorkConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="usp_GetProductOfPD"
runat="server">
<SelectParameters>
<asp:SessionParameter Name="Projectid" SessionField="Projectid" Type="string">
</asp:SessionParameter>
<asp:SessionParameter Name="productid" SessionField="productid" Type="string">
</asp:SessionParameter>
</SelectParameters>
</asp:SqlDataSource>红色部分我绑带了两个参数 但我如何跟存储过程绑带阿
@ProductSubcategoryID int
AS
SELECT ProductID, Name, ProductNumber FROM Production.Product
WHERE ProductSubcategoryID=@ProductSubcategoryID ORDER BY ProductID
Categories:
<asp:DropDownList ID="lstCategories" DataSourceID="categoriesSource" runat="server"
DataValueField="ProductSubcategoryID" DataTextField="Name" AutoPostBack="true"></asp:DropDownList>
<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>