I have two asp dropdown lists,the second one will generate options when the first dropdown list has a selected value. Both dropdown list are getting data from database. However, when I try to insert these two values into my table,the first dropdown list item will insert correctly,the second dropdown list always inserts the first item into my table.
After some testing, I found out that the second dropdown list is not selected and the first item was inserted into my table because its the default value.
BTW, my first dropdown list is autopostback
while the second one is not.
I am using Microsoft Web Developer 2010 express and I am using Visual Basic.
first dropdown list:
<asp:DropDownList ID="stockcodeddl" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="stockcode"
DataValueField="stockcode" Width="174px" Height="19px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:oakwell %>"
SelectCommand="SELECT [stockcode] FROM [orders] GROUP BY [stockcode]">
</asp:SqlDataSource>
second dropdown list:
<asp:DropDownList ID="componentddl" runat="server" DataSourceID="ComponentsByStockCode" DataTextField="component"
DataValueField="stockcode" Width="174px" Height="19px"
Enable="true" onchange="getComponent()" >
</asp:DropDownList>
<asp:TextBox ID="comtxt" runat="server"></asp:TextBox>
<asp:SqlDataSource ID="ComponentsByStockCode" runat="server"
ConnectionString="<%$ ConnectionStrings:oakwell %>"
SelectCommand="SELECT component, stockcode FROM orders WHERE ([stockcode] = @stockcode) GROUP BY stockcode, component">
<SelectParameters>
<asp:ControlParameter ControlID="stockcodeddl" Name="stockcode" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>