<asp:SqlDataSourceID="Countries" RunAt="server" ConnectionString="server=localhost;database=northwind;" SelectCommand="select distinct country from customers order by country"/> <asp:SqlDataSourceID="Customers" RunAt="server" ConnectionString="server=localhost;database=northwind;" SelectCommand="select * from customers where country =@Country"> <SelectParameters> <asp:ControlParameterName="Country" ControlID="MyDropDownList" PropertyName="SelectedValue"/> </SelectParameters> </asp:SqlDataSource> <asp:DropDownListID=" MyDropDownList" DataSourceID="Countries" DataTextField="country" AutoPostBack="true" RunAt="server"/> <asp:DataGridDataSourceID="Customers" RunAt="server"/>
2.7 调研存储过程例子
<asp:SqlDataSourceID="Countries" RunAt="server" ConnectionString="server=localhost;database=northwind;" SelectCommand="proc_GetCountries"/> <asp:SqlDataSourceID="Customers" RunAt="server" ConnectionString="server=localhost;database=northwind;" SelectCommand="proc_GetCustomers"> <SelectParameters> <asp:ControlParameterName="Country" ControlID="MyDropDownList" PropertyName="SelectedValue"/> </SelectParameters> </asp:SqlDataSource> <asp:DropDownListID="MyDropDownList" DataSourceID="Countries" DataTextField="country" AutoPostBack="true" RunAt="server"/> <asp:DataGridDataSourceID="Customers" RunAt="server"/> CREATE PROCEDURE proc_GetCustomers @Country nvarchar(32) AS SELECT * FROM Customers WHERE Country = @Country GO CREATE PROCEDURE proc_GetCustomers CREATE PROCEDURE proc_GetCountriesAS SELECT DISTINCT Country FROM Customers ORDER BY Country GO