| | |
SelectedIndexChanged in DropDownList won't trigger
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Hi,
I have two drop down lists boxes, upon page load first DDL gets populated and depending on user's selection on first DDL second DDL (child DDL) gets populated, works fine. My problem is when user goes back and makes another selection on first (parent) DDL (note that it's not a postback event, since user did not leave the page yet!! OR is that right? I am bit confused about the IsPostBack property),
So when selection in first DDL changes, it should automatically clear the Child DDL (which is still showing values for the first selection, which is deceiving)
When user actually clicks on a button to populate the Child DDL, it shows correct values for the new selection.
But when I use SelectedIndexChanged even on first DDL to clear Child DDL, it never gets triggered
This is my code
Any help is highly appreciated
First DDL is populated and now after click of a button second DDL gets populated
works great... but what if user wants to change the package (first DDL) selection, my child DDL still shows old values until user clicks on the button again.. I tried to do something like this
but the event never triggers, what am I doing wrong ?
:cry:
I have two drop down lists boxes, upon page load first DDL gets populated and depending on user's selection on first DDL second DDL (child DDL) gets populated, works fine. My problem is when user goes back and makes another selection on first (parent) DDL (note that it's not a postback event, since user did not leave the page yet!! OR is that right? I am bit confused about the IsPostBack property),
So when selection in first DDL changes, it should automatically clear the Child DDL (which is still showing values for the first selection, which is deceiving)
When user actually clicks on a button to populate the Child DDL, it shows correct values for the new selection.
But when I use SelectedIndexChanged even on first DDL to clear Child DDL, it never gets triggered
This is my code
Any help is highly appreciated
VB.NET Syntax (Toggle Plain Text)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack() Then 'Session("Current_Release_Id") = 1 Dim MySQLString As String Dim objParam1 As SqlParameter Dim MyReader As SqlDataReader Dim MyConn As SqlConnection Dim Mycmd As SqlCommand Dim MyDataAdapter As SqlDataAdapter Dim cnt As Integer Dim str As String Dim MyDataSet As New DataSet Try MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn")) MySQLString = "Select DISTINCT PackageName , PackageId " MySQLString = MySQLString + " FROM Package " MySQLString = MySQLString + "WHERE (Package.ReleaseId = @PackageRelId) ORDER BY PackageName" MyDataAdapter = New SqlDataAdapter(MySQLString, MyConn) objParam1 = MyDataAdapter.SelectCommand.Parameters.Add("@PackageRelId", SqlDbType.Int) objParam1.Value = Rel_Matrix_Id.Text.Trim str = Rel_Matrix_Id.Text.Trim PackageNameDDL.Items.Clear() If MyConn.State = ConnectionState.Closed Then MyConn.Open() End If cnt = MyDataAdapter.Fill(MyDataSet) If cnt = 0 Then ComponentDDL.Visible = False CompBtn.Visible = False Say("No Packages are Added to this Release!!") Exit Try End If ComponentDDL.Visible = True CompBtn.Visible = True 'MyDataAdapter.Dispose() PackageNameDDL.DataSource = MyDataSet PackageNameDDL.DataTextField = "PackageName" PackageNameDDL.DataValueField = "PackageId" PackageNameDDL.DataBind() MyConn.Dispose() MyConn.Close() Catch ex As Exception Say("[PageLoad] Exception " & ex.Message) System.Diagnostics.Trace.WriteLine("[ShowBtnClick] Exception " & ex.Message) Finally MyConn.Close() End Try End If End Sub
First DDL is populated and now after click of a button second DDL gets populated
VB.NET Syntax (Toggle Plain Text)
Private Sub CompBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompBtn.Click Dim MySQLString As String Dim objParam1 As SqlParameter Dim MyReader As SqlDataReader Dim MyConn As SqlConnection Dim Mycmd As SqlCommand Dim MyDataAdapter As SqlDataAdapter Dim cnt As Integer Dim str As String Dim MyDataSet As New DataSet Try MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn")) MySQLString = "Select DISTINCT ComponentID , Description " MySQLString += " FROM Component" MySQLString += " WHERE (PackageID = @PackageId) ORDER BY Description" MyDataAdapter = New SqlDataAdapter(MySQLString, MyConn) objParam1 = MyDataAdapter.SelectCommand.Parameters.Add("@PackageId", SqlDbType.Int) objParam1.Value = PackageNameDDL.SelectedItem.Value.Trim ComponentDDL.Items.Clear() If MyConn.State = ConnectionState.Closed Then MyConn.Open() End If cnt = MyDataAdapter.Fill(MyDataSet) If cnt = 0 Then Say("No Components are Added to this Package!!") Exit Try End If 'MyDataAdapter.Dispose() ComponentDDL.DataSource = MyDataSet ComponentDDL.DataTextField = "Description" ComponentDDL.DataValueField = "ComponentID" ComponentDDL.DataBind() MyConn.Dispose() MyConn.Close() Catch ex As Exception Say("[ShowComponent BtnClick] Exception " & ex.Message) System.Diagnostics.Trace.WriteLine("[ShowComponent BtnClick] Exception " & ex.Message) Finally MyConn.Close() End Try End Sub
works great... but what if user wants to change the package (first DDL) selection, my child DDL still shows old values until user clicks on the button again.. I tried to do something like this
VB.NET Syntax (Toggle Plain Text)
Private Sub PackageNameDDL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PackageNameDDL.SelectedIndexChanged ComponentDDL.Items.Clear() End Sub
:cry:
•
•
Join Date: Jan 2008
Posts: 65
Reputation:
Solved Threads: 4
•
•
•
•
Hi,
I have two drop down lists boxes, upon page load first DDL gets populated and depending on user's selection on first DDL second DDL (child DDL) gets populated, works fine. My problem is when user goes back and makes another selection on first (parent) DDL (note that it's not a postback event, since user did not leave the page yet!! OR is that right? I am bit confused about the IsPostBack property),
So when selection in first DDL changes, it should automatically clear the Child DDL (which is still showing values for the first selection, which is deceiving)
When user actually clicks on a button to populate the Child DDL, it shows correct values for the new selection.
But when I use SelectedIndexChanged even on first DDL to clear Child DDL, it never gets triggered
This is my code
Any help is highly appreciated
VB.NET Syntax (Toggle Plain Text)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack() Then 'Session("Current_Release_Id") = 1 Dim MySQLString As String Dim objParam1 As SqlParameter Dim MyReader As SqlDataReader Dim MyConn As SqlConnection Dim Mycmd As SqlCommand Dim MyDataAdapter As SqlDataAdapter Dim cnt As Integer Dim str As String Dim MyDataSet As New DataSet Try MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn")) MySQLString = "Select DISTINCT PackageName , PackageId " MySQLString = MySQLString + " FROM Package " MySQLString = MySQLString + "WHERE (Package.ReleaseId = @PackageRelId) ORDER BY PackageName" MyDataAdapter = New SqlDataAdapter(MySQLString, MyConn) objParam1 = MyDataAdapter.SelectCommand.Parameters.Add("@PackageRelId", SqlDbType.Int) objParam1.Value = Rel_Matrix_Id.Text.Trim str = Rel_Matrix_Id.Text.Trim PackageNameDDL.Items.Clear() If MyConn.State = ConnectionState.Closed Then MyConn.Open() End If cnt = MyDataAdapter.Fill(MyDataSet) If cnt = 0 Then ComponentDDL.Visible = False CompBtn.Visible = False Say("No Packages are Added to this Release!!") Exit Try End If ComponentDDL.Visible = True CompBtn.Visible = True 'MyDataAdapter.Dispose() PackageNameDDL.DataSource = MyDataSet PackageNameDDL.DataTextField = "PackageName" PackageNameDDL.DataValueField = "PackageId" PackageNameDDL.DataBind() MyConn.Dispose() MyConn.Close() Catch ex As Exception Say("[PageLoad] Exception " & ex.Message) System.Diagnostics.Trace.WriteLine("[ShowBtnClick] Exception " & ex.Message) Finally MyConn.Close() End Try End If End Sub
First DDL is populated and now after click of a button second DDL gets populated
VB.NET Syntax (Toggle Plain Text)
Private Sub CompBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompBtn.Click Dim MySQLString As String Dim objParam1 As SqlParameter Dim MyReader As SqlDataReader Dim MyConn As SqlConnection Dim Mycmd As SqlCommand Dim MyDataAdapter As SqlDataAdapter Dim cnt As Integer Dim str As String Dim MyDataSet As New DataSet Try MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn")) MySQLString = "Select DISTINCT ComponentID , Description " MySQLString += " FROM Component" MySQLString += " WHERE (PackageID = @PackageId) ORDER BY Description" MyDataAdapter = New SqlDataAdapter(MySQLString, MyConn) objParam1 = MyDataAdapter.SelectCommand.Parameters.Add("@PackageId", SqlDbType.Int) objParam1.Value = PackageNameDDL.SelectedItem.Value.Trim ComponentDDL.Items.Clear() If MyConn.State = ConnectionState.Closed Then MyConn.Open() End If cnt = MyDataAdapter.Fill(MyDataSet) If cnt = 0 Then Say("No Components are Added to this Package!!") Exit Try End If 'MyDataAdapter.Dispose() ComponentDDL.DataSource = MyDataSet ComponentDDL.DataTextField = "Description" ComponentDDL.DataValueField = "ComponentID" ComponentDDL.DataBind() MyConn.Dispose() MyConn.Close() Catch ex As Exception Say("[ShowComponent BtnClick] Exception " & ex.Message) System.Diagnostics.Trace.WriteLine("[ShowComponent BtnClick] Exception " & ex.Message) Finally MyConn.Close() End Try End Sub
works great... but what if user wants to change the package (first DDL) selection, my child DDL still shows old values until user clicks on the button again.. I tried to do something like this
but the event never triggers, what am I doing wrong ?VB.NET Syntax (Toggle Plain Text)
Private Sub PackageNameDDL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PackageNameDDL.SelectedIndexChanged ComponentDDL.Items.Clear() End Sub
:cry:
Just for giggles, try and set the SelectedIndex = -1 which should be no item selected when you make a new selection from the parent and then re-run your connection string anytime the parent SelectedIndex changes ?
![]() |
Similar Threads
- dropdownlist not firing (VB.NET)
- GetSelectedIndex Datagrid? Dropdownlist (ASP.NET)
- DropDownList (ASP.NET)
- In The DropDownList..If I have Five Names..when I click each name its index is 0 (VB.NET)
- DropDownList headache (ASP.NET)
- DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value (ASP.NET)
- How do I save an index to a particular index of a dropdownlist in a datagrid. (C#)
- Help With Datagrid RE: Creating and Saving DropDownList ReportsToID (C#)
Other Threads in the VB.NET Forum
- Previous Thread: can't binding an autoincrement field of mysql data base from vb.net
- Next Thread: Question involving text boxes...
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account application arithmetic array basic beginner browser button buttons center check click code combo crystalreport cuesent database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel exists fade file-dialog filter forms ftp generatetags hardcopy html images input insert intel listview module monitor net networking number open output panel passingparameters picturebox picturebox1 picturebox2 port print printing problem project regex right-to-left searchvb.net select settings shutdown socket sqldatbase sqlserver survey tcp temperature text textbox timespan toolbox transparency trim txttoxmlconverter user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





