DropDownList SelectedIndexChanged Event does not fire and when selecting a new item the dropdown reverts back to 0 (first item). I have a very simple Web form with two drop down controls. The first drop down works okay. It gets all of the major categories from the SQl Express database and the SelectedIndexChanged Event does fire (even though I don't need to do anything in this event). The second DropDownList control populates okay using the First DropDownList SelectedValue, but when You try to select an item, the SelectedIndexChanged event does not fire and the DropDownList index reverts to 0. I have included both the source and code behind ... I hope someone can help ... fighting this for over a day.
(DropDownList2 is the one I am having problems with):
<%@ Page Language="
VB" AutoEventWireup="false" CodeFile="AdminBusCustomerData2.aspx.
vb" Inherits="AdminBusCustomerData2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 90%">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="BusCatName" DataValueField="BusCatID">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [BusCatID], [BusCatName] FROM [BusCategory]"></asp:SqlDataSource>
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="BusSubCatName" DataValueField="BusSubCatId">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [BusSubCatId], [BusSubCatName] FROM [BusSubCategory] WHERE ([BusSubCatId] = @BusSubCatId)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="BusSubCatId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Button ID="Button1" runat="server" Enabled="False" Text="Button" Width="128px" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
... and the code behind which is doing very little:
Partial Class AdminBusCustomerData2
Inherits System.Web.UI.Page
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Button1.Enabled = True
Dim BusCatSubIdvar As String = DropDownList2.SelectedItem.Text
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
End Sub
End Class