473,698 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Fill combo on selection in asp

2 New Member
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 3265
mohana
9 New Member
u use ajax script 2 load the second combo box
Sep 29 '06 #2
sashi
1,754 Recognized Expert Top Contributor
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

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

Similar topics

4
4708
by: Sherwood Botsford | last post by:
Table Markers ID (Primary Key) This&That PointClass (Combo box) Points Table PointClasses PointClass (primary key) Points (number) Description (Text)
1
1997
by: Tom G | last post by:
Hello, I need some advice on which way to resolve the following. On a form, the user will make a selection from a combo box, after the selection several different fields need to be updated on the form, based on the selection in the combo box. I have been doing this quite successfully by having the combo box rowsource query contain all the fields and simply use the correct column to fill in the text boxes. e.g. me.txtState =...
3
2201
by: Antoine Janssen | last post by:
hi, I would like to create two combo boxes. In the first one you can select a user in the second one you can select a project. To simplify the selection i would like to shorten the project list by just presenting the projects the selected user is working on (using a where clause with the userid filled in). Does onyone know how to achieve this? Kind Regards,
4
7182
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2) how to use the selection "All" as criteria for a field in a query, which is used to generate data for a report.
1
2458
by: Birderman | last post by:
Hi is it possible to enter data into two separate fields from a single combo box selection. ie if select entry in combo, field 1 will be filled with data from column 1 of combo and field2 will be filled with data from column 2 of the combo. Anyhelp would be appreciated Regards
3
6725
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is bound to. The datatable in the dataset is filled using the typed tableadapter (TableAdapter1). DataTable consists of the typical primary key and value fields. Here is the designer generated code for ComboBox1: this.ComboBox1.DataSource =...
1
3639
by: peasedm | last post by:
Okay this one has me stumped. I have a table called Review_Statements with the following columns: statementid type statement1 statement2 statement3 I have a form called SR_Review with an unbound combo box control
1
2199
by: pctec | last post by:
Hello, I have a combo box that is looking into a field from a table named Machines, this machine table has two columns; MachineName and MachineRate but the Combo Box it only showing the MachineName field. What I want is to fill a different table with the MachineRate as soon as I select the MachineName. I’m already storing the MachineName with the Combo Box to table1 but need to extract automatically the MachineRate into a table1 as I select...
0
1601
by: dudeja.rajat | last post by:
On Sat, Aug 30, 2008 at 2:32 PM, Fredrik Lundh <fredrik@pythonware.comwrote: Fredrik, Thanks so much. That worked. Following this, I can now see that my combo2 has no previous elements and contains only the elements relevant to selection in combo1. Now, as soon as I select something in combo 2 and go back to change selection in combo1 the combo2 must get its history cleared up (i.e the previous selection in combo2's entry subwidget)
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.