有 3 个父子下拉列表,选择第 3 个下拉列表后,DetailsView 将显示所有选择的 3 个下拉列表的结果。第一个是 ServerName,第二个是 Instance,第三个是 DatabaseName。选择服务器名称的第一个下拉列表后,实例值的新列表出现在第二个下拉列表中。当我在第二个下拉列表中选择任何内容时。有一条错误消息说,“必须声明标量变量“@ServerName””。我不明白这是什么意思,请帮忙。这里有一个下拉列表代码,
<ajaxToolkit:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="ServerName" DataValueField="ServerName" DropDownStyle="Simple" MaxLength="0" style="display: inline;">
</ajaxToolkit:ComboBox>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [ServerName] FROM [tblServer]">
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="Label11" runat="server" Text="Select Instance:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownInstance" runat="server" AutoPostBack="True" DataSourceID="Instance" DataTextField="Instance" DataValueField="Instance">
</asp:DropDownList>
<asp:SqlDataSource ID="Instance" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [Instance] FROM [tblDatabase] WHERE [ServerName] = @ServerName">
<SelectParameters>
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="Label10" runat="server" Text="Select Database:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownDatabase" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="DatabaseName" DataValueField="DatabaseName">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [DatabaseName] FROM [tblDatabase] WHERE [ServerName] = @ServerName AND [Instance] = @Instance">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownInstance" Name="Instance" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
然后我将那些下拉列表函数传递给 SQLDataSource2 附带的 DetailsView,在 SQLDataSource2 中的 SelectCommand 上,我写了
SelectCommand="SELECT * FROM [tblDatabase] WHERE (([DatabaseName] = @DatabaseName) AND ([Instance] = @Instance) AND ([ServerName] = @ServerName))"
然后我添加 SelectParameter 代码,
<SelectParameters>
<asp:ControlParameter ControlID="DropDownDatabase" Name="DatabaseName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownInstance" Name="Instance" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>