中 DropDownList+DetailsView(详细视图)的使用前台绑定。
View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDvw.aspx.cs" Inherits="DropDvw" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"><title>无标题页</title></head><body><form id="form1" runat="server"><div>请选择大分类:<asp:DropDownList ID="dropYuanBo" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"DataTextField="CategoryName" DataValueField="CategoryID"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:SqlDataSource><hr />该类的产品:<asp:DetailsView ID="dvwYuanBo" runat="server" Height="50px" Width="125px" DataSourceID="SqlDataSource2"AllowPaging="True" AutoGenerateRows="False" DataKeyNames="ProductID"><Fields><asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" /><asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /><asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" /><asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /></Fields></asp:DetailsView><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice] FROM [Products] WHERE ([CategoryID] = @CategoryID)"><SelectParameters><asp:ControlParameter ControlID="dropYuanBo" DefaultValue="1" Name="CategoryID" PropertyName="SelectedValue"Type="Int32" /></SelectParameters></asp:SqlDataSource></div></form></body></html>
/web.config
<connectionStrings><add name="NorthwindConnectionString" connectionString="DataSource=.;Initial Catalog=Northwind;Integrated Security=True"providerName="System.Data.SqlClient"/></connectionStrings>
/ylbtech/WebForm-Drop-XList.rar