472,145 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

How to Fill combo on selection in asp

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
2 3188
mohana
9
u use ajax script 2 load the second combo box
Sep 29 '06 #2
sashi
1,754 Expert 1GB
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.

Similar topics

4 posts views Thread by Sherwood Botsford | last post: by
3 posts views Thread by Antoine Janssen | last post: by
reply views Thread by dudeja.rajat | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.