Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > ASP.NET

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 04-26-2000, 08:04 AM
siobhan
Guest
 
Posts: n/a
drop down list populated from a d/base


Can anyone tell me how to create a drop down list populated from a d/base
using vbscript or jscript. Can this be done or do you have to use HTML.
many thanks in advance
Reply With Quote
  #2  
Old 04-26-2000, 11:18 AM
Carl Cirillo
Guest
 
Posts: n/a
Re: drop down list populated from a d/base


Here's a snippet of code that uses ADO and ASP (JScript) to call a stored
procedure which returns in a recordset, names of email domains. That recordset
is then iterated through and the drop down list options are created.

If you're not using ASP, you can still convert the script to run on the client
side.


Response.write('<select name="domain" size="1">');
dbConn = Server.CreateObject("ADODB.Connection");
dbConn.Open( Application("db_name"), Application("db_login"), Application("db_pwd")
);
dbCmd = Server.CreateObject("ADODB.Command");
dbCmd.ActiveConnection = dbConn;
dbCmd.CommandType = 4;
dbCmd.CommandText = "user_aliasDomainList";
dbRows = Server.CreateObject("ADODB.Recordset");
dbRows.Open( dbCmd );
while (!dbRows.EOF) {
Response.write('<option value="'+dbRows("domain_name").value+'">'+dbRows("domain_name").value+'</option>');
dbRows.moveNext();
}
Response.write('</select>');
dbRows.close();
dbConn.close();


-carl


"siobhan" <sib121@aol.com> wrote:
>
>Can anyone tell me how to create a drop down list populated from a d/base
>using vbscript or jscript. Can this be done or do you have to use HTML.
>many thanks in advance


Reply With Quote
  #3  
Old 04-27-2000, 05:41 PM
Matthew
Guest
 
Posts: n/a
Re: drop down list populated from a d/base


"siobhan" <sib121@aol.com> wrote:
>
>Can anyone tell me how to create a drop down list populated from a d/base
>using vbscript or jscript. Can this be done or do you have to use HTML.
>many thanks in advance


Here is some ASP code that uses a variant array that a VB Built component
gets from a database to populate a listbox ("<Select>") control on an html
form. The code simply steps through the array concatenating a string representing
the option tag that will be sent back to the browser via the Response object.
Your own solution will depend largely on how you get data out of the database
- but here is mine:

<select name="SelList" size="20" style="width=100%" >
<%
If isarray(vData) and not isnull(vData) then
for i = 0 to lngMax
strID = vData(0,i)
strName = vData(1,i)
strCompany = vData(2,i)
strOption = "<option value=" & strID & ">" & strName & " of " & strCompany

response.write strOption
next
end if
%>
</select>

Good luck
Reply With Quote
  #4  
Old 04-28-2000, 08:43 PM
Mark Hensel
Guest
 
Posts: n/a
Re: drop down list populated from a d/base


Here's another suggestion using the GetRows method to take a recordset and
populate it into a two-dimensional array (which is always the case). This
is in VBScript.

<%
set conn = server.CreateObject("ADODB.Connection")

SQL = "select foo, foo_two from tbl_foo"

set rs = conn.Execute(SQL)

if rs.BOF and rs.EOF then
blnRun = False
else
blnRun = True
arrFoo = rs.GetRows() 'returns all records in rs
end if

rs.close
set rs = nothing
conn.close
set conn = nothing

if blnRun then
response.write "<select name=""foo"">" & vbcrlf
for x = 0 to UBound(arrFoo,2) ' iterates through records
response.write "<option value="""&arrFoo(0,x)&""">"&arrFoo(1,x)&"</option>"
& vbcrlf
next
end if
%>

Have Fun!

Reply With Quote
  #5  
Old 06-07-2000, 03:04 AM
Mujtaba Joad
Guest
 
Posts: n/a
Re: drop down list populated from a d/base


Another method which will basically increase the performance is -

1. Use a trigger to write to a file whenever the database table is updated.
The text in this file will be of type

<select name=x>
<option value = 1>One</option>
<option value = 2>Two</option>
<option value = 3>Three</option>
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 02:48 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.