Microsoft KB Archive/175426: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 61: | Line 61: | ||
<BODY> | <BODY> | ||
<BR>This is an HTML ListBox<BR> | <BR>This is an HTML ListBox<BR> | ||
<SELECT NAME= | <SELECT NAME="ListBox" SIZE=1> | ||
<% Set conn = Server.CreateObject( | <% Set conn = Server.CreateObject("ADODB.Connection") %> | ||
<% conn.Open | <% conn.Open "DSN=AdvWorks" ' connect to the database %> | ||
<% Set rs = conn.Execute( | <% Set rs = conn.Execute("SELECT City FROM Customers") %> | ||
<% Do While Not rs.EOF ' define the ListBox OPTIONs %> | <% Do While Not rs.EOF ' define the ListBox OPTIONs %> | ||
<OPTION VALUE= | <OPTION VALUE="<%= rs("City") %>"> <%= rs("City") %> | ||
<% rs.MoveNext %> | <% rs.MoveNext %> | ||
<% Loop %> | <% Loop %> | ||
Line 76: | Line 76: | ||
</pre> | </pre> | ||
The following code demonstrates how to load values into an ActiveX ComboBox control. Be aware that this control must be installed and registered on your system in order for this sample to work correctly: | The following code demonstrates how to load values into an ActiveX ComboBox control. Be aware that this control must be installed and registered on your system in order for this sample to work correctly: | ||
<pre class="codesample"> <%@ LANGUAGE= | <pre class="codesample"> <%@ LANGUAGE="VBSCRIPT" %> | ||
<HTML> | <HTML> | ||
<BODY> | <BODY> | ||
<BR>This is an ActiveX ComboBox control<BR> | <BR>This is an ActiveX ComboBox control<BR> | ||
<!-- insert the ActiveX control into the HTML page --> | <!-- insert the ActiveX control into the HTML page --> | ||
<OBJECT ID= | <OBJECT ID="ComboBox" WIDTH=96 HEIGHT=24 | ||
CLASSID= | CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3"> | ||
</OBJECT> | </OBJECT> | ||
<SCRIPT LANGUAGE= | <SCRIPT LANGUAGE="VBScript"> | ||
<!-- | <!-- | ||
' load the ActiveX control after the window has been loaded | ' load the ActiveX control after the window has been loaded | ||
Sub Window_OnLoad() | Sub Window_OnLoad() | ||
<% Set conn = Server.CreateObject( | <% Set conn = Server.CreateObject("ADODB.Connection") %> | ||
<% conn.Open | <% conn.Open "DSN=AdvWorks" ' connect to the database %> | ||
<% Set rs = conn.Execute( | <% Set rs = conn.Execute("SELECT City FROM Customers") %> | ||
<% Do While Not rs.EOF %> | <% Do While Not rs.EOF %> | ||
thisForm:ComboBox.AddItem( | thisForm:ComboBox.AddItem("<%= rs("City") %>") ' Do an AddItem for | ||
' each record | ' each record | ||
<% rs.MoveNext %> | <% rs.MoveNext %> |
Latest revision as of 11:07, 21 July 2020
Article ID: 175426
Article Last Modified on 5/2/2006
APPLIES TO
- Microsoft Active Server Pages 4.0
- Microsoft Visual InterDev 1.0 Standard Edition
- Microsoft Internet Information Server 4.0
- Microsoft Internet Information Services 5.0
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
This article was previously published under Q175426
SUMMARY
This article demonstrates how to load a ComboBox with records that are retrieved from a database. This example creates an Active Server Pages (ASP) page that connects to the Adventure Works database.
MORE INFORMATION
The following code demonstrates how to load values into an HTML list box:
<HTML> <BODY> <BR>This is an HTML ListBox<BR> <SELECT NAME="ListBox" SIZE=1> <% Set conn = Server.CreateObject("ADODB.Connection") %> <% conn.Open "DSN=AdvWorks" ' connect to the database %> <% Set rs = conn.Execute("SELECT City FROM Customers") %> <% Do While Not rs.EOF ' define the ListBox OPTIONs %> <OPTION VALUE="<%= rs("City") %>"> <%= rs("City") %> <% rs.MoveNext %> <% Loop %> <% rs.Close %> <% conn.Close %> </SELECT> </BODY> </HTML>
The following code demonstrates how to load values into an ActiveX ComboBox control. Be aware that this control must be installed and registered on your system in order for this sample to work correctly:
<%@ LANGUAGE="VBSCRIPT" %> <HTML> <BODY> <BR>This is an ActiveX ComboBox control<BR> <!-- insert the ActiveX control into the HTML page --> <OBJECT ID="ComboBox" WIDTH=96 HEIGHT=24 CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3"> </OBJECT> <SCRIPT LANGUAGE="VBScript"> <!-- ' load the ActiveX control after the window has been loaded Sub Window_OnLoad() <% Set conn = Server.CreateObject("ADODB.Connection") %> <% conn.Open "DSN=AdvWorks" ' connect to the database %> <% Set rs = conn.Execute("SELECT City FROM Customers") %> <% Do While Not rs.EOF %> thisForm:ComboBox.AddItem("<%= rs("City") %>") ' Do an AddItem for ' each record <% rs.MoveNext %> <% Loop %> <% rs.Close %> <% conn.Close %> End Sub --> </SCRIPT> </BODY> </HTML>
NOTE: Use your browser to view these pages and the view the HTML source. This will give you a better understanding of what code was produced by ASP.
REFERENCES
For the latest Knowledge Base artices and other support information on Visual InterDev and Active Server Pages, see the following page on the Microsoft Technical Support site:
Keywords: kbhowto kbscript kbcodesnippet kbdatabase KB175426