Reputation: 47
I'm working on C#, Visual studio 2012
I have Two Dropdownlists.
In first dropdownlist it shows list of the name of students (from the table [students])..... in second dropdownlist it shows majors (from the table [courses]).
These two will comes from database which contains two tables ( students and courses ).
Suppose when the user select the student from 1st dropdownlist so,in the other dropdownlist it should show related major to that student.
How to do this using asp.net web applications without programming.
Thanks.
Upvotes: 0
Views: 761
Reputation: 62260
I think you meant to say no code behind instead of without programming.
You can use SQL DataSources.
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>
Note: Make sure that AutoPostBack="True" for DropDownListStudent
Upvotes: 4