我正在尝试在表单视图中创建两个下拉列表,其中第二个下拉列表中显示的值取决于第一个下拉列表。第一个列表包含 sql 表“类”中包含的类号,第二个下拉列表包含同一 sql 表“类”中的类部分。我希望能够选择一个班级编号,并且只弹出与该班级编号相对应的部分。
示例类表:
Number: Section: SLN:
210 1 A-1
210 2 A-2
210 3 A-3
340 1 B-1
340 7 B-7
我目前使用正确设置了第一个号码列表
<asp:DropDownList ID="ddlNumber" runat="server"
DataSourceID="SqlDSClasses"
AutoPostBack="True" DataTextField="Number" DataValueField="Number">
</asp:DropDownList>
for the drop down and
<asp:SqlDataSource ID="SqlDSClasses" runat="server"
ConnectionString="<%$ ConnectionStrings:ReinstatementCS %>"
SelectCommand="SELECT [Prefix], [Number], [Location], [SLN],
[StartTime], [EndTime], [ClassDay], [ClassCredit], [ClassSection] FROM [Classes]">
</asp:SqlDataSource>
for the corresponding SqlDataSource
到目前为止,我已经尝试使用
SELECT [ClassSection] FROM [Classes] WHERE [Number] = NumberDropDownList.DataValueField
for the Section list:
<asp:DropDownList ID="ClassSectionDropDownList" runat="server" DataSourceID="SqlDSNumSec"
DataTextField="ClassSection" DataValueField="ClassSection" AutoPostBack="True">
</asp:DropDownList>
正在使用的表单视图设置如下:
<asp:FormView ID="FVStudentClass" runat="server" DataSourceID="SqlDSStudentClass"
DataSourceID2="SqlDSAccess" EmptyDataText="Student Class Not Completed">
<EditItemTemplate>
<table style="width:100%;">
<tr>
<td>
Prefix:
</td>
<td>
UCOLL</td>
<td>
Number:
</td>
<td>
<asp:DropDownList ID="ddlNumber" runat="server" DataSourceID="SqlDSClasses" AutoPostBack="True"
DataTextField="Number" DataValueField="Number">
</asp:DropDownList>
</td>
<td>
Section:
</td>
<td>
<asp:DropDownList ID="SectionDropDownList" runat="server" DataSourceID="SqlDSNumSec"
DataTextField="Section" DataValueField="Section" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
</table>
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
IsTransfer:
<asp:CheckBox ID="IsTransferCheckBox" runat="server"
Checked='<%# Bind("IsTransfer") %>' />
<br />
Prefix:
<asp:TextBox ID="PrefixTextBox" runat="server" Text='<%# Bind("Prefix") %>' />
<br />
Number:
<asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>' />
<br />
Section:
<asp:TextBox ID="SectionTextBox" runat="server"
Text='<%# Bind("Section") %>' />
<br />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<table style="width:100%;">
<tr>
<td>
Prefix:</td>
<td>
<asp:Label ID="PrefixLabel" runat="server" Text='<%# Bind("Prefix") %>' />
</td>
<td>
Number:</td>
<td>
<asp:Label ID="NumberLabel" runat="server" Text='<%# Bind("Number") %>' />
</td>
<td>
ClassSection:</td>
<td>
<asp:Label ID="ClassSectionLabel" runat="server"
Text='<%# Bind("ClassSection") %>' />
</td>
</tr>
<tr>
<td>
IsTransfer:</td>
<td>
<asp:CheckBox ID="IsTransferCheckBox" runat="server"
Checked='<%# Bind("IsTransfer") %>' Enabled="false" />
</td>
</tr>
</table>
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit" />
</ItemTemplate>
</asp:FormView>
使用 SqlDataSource:
<asp:SqlDataSource ID="SqlDSStudentClass" runat="server" ConnectionString="<%$ ConnectionStrings:ReinstatementCS %>"
DeleteCommand="DELETE FROM [StudentClass] WHERE [SLN] = @SLN"
InsertCommand="INSERT INTO [StudentClass] ([SLN],[ID]) VALUES (@SLN, @ID)"
SelectCommand="SELECT DISTINCT Classes.Number, Classes.Section, StudentClass.ID
FROM
StudentClass
LEFT JOIN AccessList ON AccessList.ALID = StudentClass.ID
JOIN Classes ON StudentClass.SLN = Classes.SLN
WHERE ([SLN] = @SLN)"
<!--AccessList just gives extra information to the user-->
UpdateCommand="UPDATE [StudentClass] SET [SLN] = @SLN, [ID] = @ID WHERE [SLN] = @SLN">
<DeleteParameters>
<asp:Parameter Name="SLN" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="SLN" Type="String" />
<asp:Parameter Name="ID" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ALID"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="String" />
<asp:Parameter Name="SLN" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
使用上述示例表的表单示例:
Number Drop Down:
210 -> select 210
340
Section Drop Down:
1
2 -> select 3
3