问题描述
我在PETSHOP4.0架构中有两个表,一个表是省份,一个表是城市,省份表中有ID(序号),TITLE(省份名称),PID(省份代码)城市表中有CID(城市ID),PID(省份ID),TITLE(城市名称)其他几个层全部都搞好了,现在我想在页面层中实现,省份的下拉列表框中选择"江苏省",在市的那个下拉列表框就会有"南京市","苏州市",等等;在省份的下拉列表框中选择"浙江省",在市的那个下拉列表框就会有"杭州市","宁波市",等等;我是菜鸟,期盼高手指点.....万分感谢!
解决方案
解决方案二:
实现无刷新联动是最好的选择,当然也就要用到AJAX了,下面给出两种方案,第一种要刷新,第二种无刷新:方案一:<div><asp:DropDownListID="ddl1"runat="server"DataSourceID="SqlDataSource1"AutoPostBack="true"DataTextField="TITLE"DataValueField="PID"></asp:DropDownList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStrings:你的连接字符串%>"SelectCommand="SELECT*FROM[省份表名]"></asp:SqlDataSource></div><div><asp:DropDownListID="ddl2"runat="server"DataSourceID="SqlDataSource2"DataTextField="TITLE"DataValueField="CID"></asp:DropDownList><asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ConnectionStrings:你的连接字符串%>"SelectCommand="SELECT*FROM[城市表名]WHERE([PID]=@PID)"><SelectParameters><asp:ControlParameterControlID="ddl1"Name="PID"PropertyName="SelectedValue"Type="String"/></SelectParameters></asp:SqlDataSource></div>
方案二:<asp:ScriptManagerID="ScriptManager1"runat="server"/><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><div><asp:DropDownListID="ddl1"runat="server"DataSourceID="SqlDataSource1"AutoPostBack="true"DataTextField="TITLE"DataValueField="PID"></asp:DropDownList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStrings:你的连接字符串%>"SelectCommand="SELECT*FROM[省份表名]"></asp:SqlDataSource></div><div><asp:DropDownListID="ddl2"runat="server"DataSourceID="SqlDataSource2"DataTextField="TITLE"DataValueField="CID"></asp:DropDownList><asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ConnectionStrings:你的连接字符串%>"SelectCommand="SELECT*FROM[城市表名]WHERE([PID]=@PID)"><SelectParameters><asp:ControlParameterControlID="ddl1"Name="PID"PropertyName="SelectedValue"Type="String"/></SelectParameters></asp:SqlDataSource></div></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="ddl1"EventName="SelectedIndexChanged"/></Triggers></asp:UpdatePanel>
如果还有什么问题,可以与我联系:QQ48505424