我似乎无法弄清楚我在哪里出错了。我有两个列表框,第一个从 sql 服务器上的存储过程中提取数据。the second list box is supposed to populate when the an item in the first list box is selected. 当单击第一个列表框中的项目时,第二个列表框的存储过程应传递所选项目的文本。问题是第二个列表框没有填充。我将不胜感激任何有用的反馈,或者可能是一种更简单的方法来完成我正在尝试做的事情。
ASP.NET:
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="LOCATION" DataTextField="L_Name" DataValueField="L_Name" AutoPostBack="True"></asp:ListBox>
<asp:SqlDataSource ID="LOCATION" runat="server" ConnectionString="<%$ ConnectionStrings:SAMC_2ConnectionString %>" SelectCommand="L_Get" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:ListBox ID="ListBox2" runat="server" Height="150px" Width="200px" AutoPostBack="True" DataTextField="C_Name" DataValueField="C_Name" />
<asp:SqlDataSource ID="CompByLocal" runat="server" ConnectionString="<%$ ConnectionStrings:SAMC_2ConnectionString %>" SelectCommand="L_Get_C" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ListBox1" DefaultValue="" Name="L_Name" PropertyName="SelectedValue" Type="String" />
<asp:Parameter Name="L_ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
VB.NET:
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim val As String = ListBox1.Items(ListBox1.SelectedIndex).ToString
TextBox1.Text = val
ListBox2.Items.Clear()
ListBox2.DataSource = CompByLocal
ListBox2.DataBind()
End Sub