By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,506 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,506 IT Pros & Developers. It's quick & easy.

How to Fill combo on selection in asp

P: 2
Hi,

I am Using 2 combo i am filling 1st combo through data base value like company name.

i want to fill the name of employee in second combo when i select company name from first combo

can any body help me in this regards.
Sep 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: 9
u use ajax script 2 load the second combo box
Sep 29 '06 #2

sashi
Expert 100+
P: 1,754
Hi there,

Kindly refer to below sample code segment, hope it helps, take care my fren.. :)

Expand|Select|Wrap|Line Numbers
  1. <!-- #include file="adovbs.inc" -->
  2. <%
  3. Dim strSQL
  4. Dim cnnSalesDB
  5. Dim rstSalesmen, rstSales
  6. Dim iRequestedID
  7.  
  8. ' Some basic checking and cleaning of the input
  9. iRequestedID = Trim(Request.QueryString("id"))
  10. iRequestedID = Replace(iRequestedID, "'", "''")
  11.  
  12. If IsNumeric(iRequestedID) Then
  13.     iRequestedID = CInt(iRequestedID)
  14. Else
  15.     iRequestedID = 0
  16. End If
  17.  
  18. ' The form links back to this same file passing back the id
  19. %>
  20. <p>
  21. Pick a salesman to see the details of one of their sales:
  22. </p>
  23. <form action="db_pulldown_linked.asp" method="get">
  24. <%
  25.  
  26. ' Create ADO data connection object
  27. Set cnnSalesDB = Server.CreateObject("ADODB.Connection")
  28.  
  29. ' Open data connection - Use this line to use Access
  30. 'cnnSalesDB.Open "DBQ=" & Server.MapPath("MyData.mdb") & ";" _
  31. '    & "Driver={Microsoft Access Driver (*.mdb)};", "admin", ""
  32.  
  33. ' Open data connection - Our SQL Server code
  34. cnnSalesDB.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
  35.     & "Initial Catalog=samples;Connect Timeout=15;" _
  36.     & "Network Library=dbmssocn;", "samples", "password"
  37.  
  38. ' Build our query for select box 1
  39. strSQL = "SELECT * FROM sample ORDER BY last_name;"
  40.  
  41. ' Create and open recordset object using existing connection
  42. Set rstSalesmen = Server.CreateObject("ADODB.Recordset")
  43. rstSalesmen.Open strSQL, cnnSalesDB, adOpenForwardOnly, adLockOptimistic, adCmdText
  44.  
  45. ' Build our drop down box of salesmen names
  46. If Not rstSalesmen.EOF Then
  47.     rstSalesmen.MoveFirst
  48.     %>
  49.     <select name="id">
  50.         <option></option>
  51.         <% ' Loop through names
  52.         Do While Not rstSalesmen.EOF
  53.             Response.Write "<option value="""
  54.             Response.Write rstSalesmen.Fields("id")
  55.             Response.Write """"
  56.             If rstSalesmen.Fields("id") = CInt(iRequestedID) Then
  57.                 Response.Write "selected=""true"""
  58.             End If
  59.             Response.Write ">"
  60.             Response.Write Trim(rstSalesmen.Fields("first_name"))
  61.             Response.Write " "
  62.             Response.Write Trim(rstSalesmen.Fields("last_name"))
  63.             Response.Write "</option>" & vbCrLf
  64.  
  65.             ' Move to next record
  66.             rstSalesmen.MoveNext
  67.         Loop
  68.         %>
  69.     </select>
  70.     <%
  71. End If
  72.  
  73. ' Close ADO objects we're finished with and free DB variables
  74. rstSalesmen.Close
  75. Set rstSalesmen =  Nothing
  76.  
  77. ' If a request for a specific id comes in, then build second select box
  78. If iRequestedID <> 0 Then
  79.     strSQL = "SELECT * FROM sales WHERE SalesmanId = " _
  80.         & iRequestedID & " ORDER BY timestamp"
  81.  
  82.     Set rstSales = Server.CreateObject("ADODB.Recordset")
  83.     rstSales.Open strSQL, cnnSalesDB, adOpenForwardOnly, adLockOptimistic, adCmdText
  84.  
  85.     ' Build our drop down box of the salesmen's sales
  86.     If Not rstSales.EOF Then
  87.         rstSales.MoveFirst
  88.         %>
  89.         <select name="sale">
  90.             <option></option>
  91.             <% ' Loop through names
  92.             Do While Not rstSales.EOF
  93.                 Response.Write "<option>$"
  94.                 Response.Write Trim(rstSales.Fields("amount"))
  95.                 Response.Write " on "
  96.                 Response.Write Trim(rstSales.Fields("timestamp"))
  97.                 Response.Write "</option>" & vbCrLf
  98.  
  99.                 ' Move to next record
  100.                 rstSales.MoveNext
  101.             Loop
  102.             %>
  103.         </select>
  104.         <%
  105.     End If
  106.  
  107.     ' Close ADO objects we're finished with and free DB variables
  108.     rstSales.Close
  109.     Set rstSales =  Nothing
  110. End If
  111.  
  112. ' Close ADO objects we're finished with and free DB variables
  113. cnnSalesDB.Close
  114. Set cnnSalesDB = Nothing
  115. %>
  116. <input type="submit" value="Submit" />
  117. </form>
  118.  
Sep 29 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.