[英]How to populate a drop down list from another drop down list
我正在使用C#,Visual Studio 2012
我有两个下拉列表。
在第一个下拉列表中,显示学生姓名列表(来自[students]表).....在第二个下拉列表中,其显示专业(从表格[courses]中)。
这两个将来自包含两个表(学生和课程)的数据库。
假设当用户从第一个下拉列表中选择该学生时,在另一个下拉列表中它应显示与该学生相关的专业。
如何使用asp.net Web应用程序而不进行编程。
谢谢。
我认为您的意思是说没有背后的代码,而不是没有编程 。
您可以使用SQL数据源。
StudentId | StudentName
----------+-------------
1 | Jon
2 | Marry
CourseId | CourseName | StudentId
---------+------------+----------
1 | Physic | 1
2 | Math | 1
3 | Physic | 2
4 | English | 2
<asp:DropDownList ID="DropDownListStudent" runat="server"
DataSourceID="StudentSqlDataSource"
DataTextField="Name" DataValueField="StudentId" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="StudentSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT StudentId, StudentName FROM [Student]">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownListCourse" runat="server"
DataSourceID="CourseSqlDataSource" DataTextField="CourseName"
DataValueField="CourseId">
</asp:DropDownList>
<asp:SqlDataSource ID="CourseSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Course] WHERE StudentId=@StudentId">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownListStudent"
PropertyName="SelectedValue"
Name="StudentId" Type="Int32" DefaultValue="1" />
</SelectParameters>
</asp:SqlDataSource>
注意:确保DropDownListStudent的AutoPostBack =“ True”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.