Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically linked combo box fill another combo box 1

Status
Not open for further replies.

hsingh1981

Programmer
Apr 8, 2008
56
GB
Hi all,



I'm fairly new to asp.net. Am using vb.net in my asp pages. I have combo box named location, if a user selects London or edinburgh. I would like it to populate the other combo box called destination.

How do i do this? I can fill the combo box using this code



Code:
	 sub Fill_Location()
	' to populate combo box
	    Dim conn As New ADODB.Connection
        Dim rs As New ADODB.Recordset

        Try
            conn.Open(application("dblocation"))
        Catch ex As Exception
            'MsgBox("ERROR: Database cannot be opened. See system administrator. MESSAGE: " + ex.Message.ToString, MsgBoxStyle.Critical, "APPLICATION ERROR")
            Exit Sub
        End Try


        rs.Open("Ref_Location", conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        rs.MoveFirst()
        Do While Not rs.EOF
            Location.Items.Add(rs.Fields("Location").Value)
            rs.MoveNext()
        Loop
        rs.Close()
		conn.Close()
	  end sub


But don't know how to trigger the action when the location combo box is picked by the user, so to populate the destination combo box?



many thanks
 
1st. use ADO.Net objects, not ADODB.
2nd. Msgbox will not do anything in asp.net vb/c# runs on the server. the html is presented on the client(browser)
3rd. you need to either use a try/finally block, or a using block. your try/catch will cause problems if an error is thrown while reading the records.

to answer your question
define a handler for the selected index changed event for dropdown A
populate dropdown A use the datasource/databind
within the selected index changed event.
validate the user selected a valid item from the dropdown
populate dropdown B
set the selected index property to the correct value.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top