| | |
DropDownList
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Solved Threads: 0
I have 2 DropDownList in a single page.The 1st contain department name and the 2nd contain employee name.When I click the 1st DropDownList , the 2nd will display the employee name which are under that department.The problem is the 2nd DropDownList will display redundant data and when I choose another department, the new employee name will add to the previous employee list in the 2nd DropDownList.
My code:
The 1st DropDownList= cboJbtn
2nd DropDownList= cboNama
My code:
ASP.NET Syntax (Toggle Plain Text)
Protected Sub cboJbtn_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboJbtn.SelectedIndexChanged ConnDb(cboJbtn.SelectedItem.Text) End Sub Private Sub ConnDb(ByVal jbtn As String) Dim MyConn As SqlConnection = New SqlConnection("Data Source=WIN200;Initial Catalog=***;User ID=***;Password=***") Dim cmd As String = "SELECT DISTINCT dataStaf.nama FROM dataStaf INNER JOIN service ON dataStaf.idStaf = service.idStaf INNER JOIN databahagian ON service.kdjbts = databahagian.kodBahagian WHERE (dataStaf.status = '1') AND (databahagian.namaBahagian ='" & jbtn & "') ORDER BY dataStaf.nama" Dim MyCmd As New SqlCommand(cmd, MyConn) 'MyCmd.CommandType = CommandType.Text Try If MyConn.State = ConnectionState.Closed Then MyConn.Open() End If cboNama.DataSource = MyCmd.ExecuteReader() cboNama.DataTextField = "nama" cboNama.DataValueField = "nama" cboNama.DataBind() MyConn.Close() Catch ex As Exception lblMsg.Text = "Error connecting to db" End Try End Sub End Class
2nd DropDownList= cboNama
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Solved Threads: 0
Yes. I did set the autopostback of both the dropdownlist to true. It seem that my program will run the cboJbtn_SelectedItemIndex twice.
I have put a control in cboJbtn_SelectedItemIndex so that it will not call the ConnDb function twice. But I appreciate it if anyone can tell me how to prevent it without using any control.
Thanks in advance, and also thanks to Exelio for your reply
•
•
•
•
The coding which u sent seems to be ok.Did you set the autopostback property of both the dropdownlists to be true.
Thanks in advance, and also thanks to Exelio for your reply
Last edited by yatt; Sep 5th, 2006 at 10:14 pm.
![]() |
Similar Threads
- dropdownlist value doesnt get selected (ASP)
- GetSelectedIndex Datagrid? Dropdownlist (ASP.NET)
- disable dropdownlist with javascript (JavaScript / DHTML / AJAX)
- Help with dropdownlist data adding? (VB.NET)
- DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value (ASP.NET)
- GetSelectedIndex Datagrid? Dropdownlist (C#)
- 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 ASP.NET Forum
- Previous Thread: Access to the path is denied
- Next Thread: ASP.Net Error
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox child class compatible complex content contenttype control countryselector courier database datagrid datagridview datalist deployment development dgv dialog dropdown dropdownmenu dynamic dynamically edit editing embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv folder form gridview gudi iis image javascript languages list maps menu mobile mssql nameisnotdeclared novell opera order problem profile ratings redirect refer registration relationaldatabases reportemail response.redirect rows search security select serializesmo.table sessionvariables silverlight smoobjects software sql ssl tracking treeview typeof validatedate validation vb.net vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xsl





