How to add items to ASP.NET DropDown List through client side VBSCRIPT

I tried out the code but i am not able to add option text.

Page 1 of 1

2 Replies - 16571 Views - Last Post: 22 May 2008 - 08:45 AM Rate Topic: -----

#1 Jhanvy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-May 08

How to add items to ASP.NET DropDown List through client side VBSCRIPT

Posted 14 May 2008 - 11:49 PM

Sub GO()

	'Create the ASPPrinter object
	Set Prn=CreateObject("ASPPrinterCOM.ASPPrinter")
	'Call the GetPrinters method
				 Printers=Prn.GetPrinters(PrintersCount)
	'P = PrintersCount & " printers were detected on your system:" 
	For i=0 To Ubound(Printers)
dim opt
opt=document.createElement("option")
' Add an Option object to Drop Down/List Box
opt.text = Printers(i)
'MsgBox "OPTION"&opt.text
 opt.value = Printers(i) 
 document.getElementById"DropDownList1").options.add(opt)		
'Assign text and value to Option object
Next
Set Prn=Nothing
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: How to add items to ASP.NET DropDown List through client side VBSCRIPT

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How to add items to ASP.NET DropDown List through client side VBSCRIPT

Posted 15 May 2008 - 08:27 AM

Moved to ASP.NET.
Was This Post Helpful? 0
  • +
  • -

#3 ajwsurfer   User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 385
  • Joined: 24-October 06

Re: How to add items to ASP.NET DropDown List through client side VBSCRIPT

Posted 22 May 2008 - 08:45 AM

This looks good except for the typo:
document.getElementById"DropDownList1").options.add(opt) 

'should be 

document.getElementById("DropDownList1").options.add(opt) 



I have VS 2008 and it seems that the line would work like this:
  Sub GO()

	'Create the ASPPrinter object
	Set Prn=CreateObject("ASPPrinterCOM.ASPPrinter")
	'Call the GetPrinters method
	Printers=Prn.GetPrinters(PrintersCount)
	'P = PrintersCount & " printers were detected on your system:"
	For i=0 To Ubound(Printers)
			
		document.getElementById("DropDownList1").Items.Add(Printers(i))
	
	 Next
	 Set Prn=Nothing
End Sub



But I would try to build a string of printer names, and display them to the screen first, just to make sure that they are really there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1