Mohammed Atef’s Technical blog

AutoComplete DropDownList using JavaScript

Introduction

Today I am going to present VB.net method that create AutoComplete DropDownlist dynamically .I have used JavaScript code for generating AutoComplete DropDownlist from this site

I have created two methods one for creating dropdown list and another to create Div control dynamically. second method use RegisterStartupScript method for registering some java script code used in my sample.

First method code like following

Public Function CreateDDL() As DropDownList
Dim ddl As DropDownList
ddl = New DropDownList
ddl.Attributes.Add(“name”, “alfa1”)
ddl.ID = “combo_zone1”
ddl.Items.Add(“aaaa”)
ddl.Items.Add(“aa1”)
ddl.Items.Add(“aas”)
ddl.Items.Add(“asdf”)
ddl.Items.Add(“bbb”)
ddl.Items.Add(“b111”)
ddl.Items.Add(“bbb43”)
ddl.Items.Add(“ddd”)
ddl.Items.Add(“dbbd”)
ddl.Items.Add(“eee”)
ddl.Items.Add(“eeea”)
ddl.Items.Add(“aase”)
ddl.Items.Add(“nnnmmm”)
ddl.Visible = True
Return ddl
End Function

I think it is clear method I have just create DropDownlist and assign name attribute and id for it and finally added some items

Second method fond below

Public Sub CreateDiv()
Dim dv As New HtmlControls.HtmlGenericControl(“DIV”)
dv.ID = “newdv”
dv.Attributes.Add(“class”, “content”)
dv.Controls.Add(CreateDDL())
Dim scriptstr As String = “”
scriptstr = “<script type=’text/javascript’>”
scriptstr = scriptstr + ” ” + “var z=dhtmlXComboFromSelect(‘combo_zone1’);”
scriptstr = scriptstr + ” ” + “z.enableFilteringMode(true);”
scriptstr = scriptstr + ” ” + “</script>”
dv.Visible = True
form1.Controls.Add(dv)
Page.ClientScript.RegisterStartupScript(Me.GetType(), “startup”, scriptstr)
End Sub

At this method I have created div control dynamically

And I have added the DropDownlist control from by calling the first method and finally I have register the JavaScript code into this div.

You can donload full sample from here

I hope that helped.

Advertisements

September 13, 2009 - Posted by | Asp.net | , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: