Fórum Como montar uma rotina de Pesquisa Dinamica numa DropDownList ASP.NET #2784
13/02/2009
0
Sergio Santos
Curtir tópico
+ 0Posts
13/02/2009
[devmedia .net]
<script type="text/javascript" language="JavaScript"> function inicializar() { if (document.getElementById("ddlAgencia") != null) //ddlAgência é o id do DropDownList cc1 = new ComboCompletion(document.getElementById("ddlAgencia"), document.getElementById("divAgencia")); //divAgência é o id da Div onde vai aparecer o que você digitou ao colocar o foco no dropdown if (document.getElementById("ddlFuncionario") != null) cc1 = new ComboCompletion(document.getElementById("ddlFuncionario"), document.getElementById("divFuncionario")); if (document.getElementById("ddlProduto") != null) cc1 = new ComboCompletion(document.getElementById("ddlProduto"), document.getElementById("divProduto")); if (document.getElementById("ddlSegmento") != null) cc1 = new ComboCompletion(document.getElementById("ddlSegmento"), document.getElementById("divSegmento")); } window.onload = inicializar; </script> Esse é o método que faz a busca no dropdown function ComboCompletion(object, informationArea) { this.object = object; this.searchPattern = ""; this.informationArea = informationArea; this.onChanged = null; this.updateInformationArea = function() { if (this.informationArea != null) { this.informationArea.innerText = this.searchPattern; } } this.updateToFirstMatch = function() { var i; var options = this.object.options; for(i = 0, l = options.length; i < l; i++) { if (options[i].text.toUpperCase().indexOf(this.searchPattern) == 0) { this.object.selectedIndex = i; return; } } } this.keyUp = function() { if ((event.keyCode == 37) || (event.keyCode == 38) || (event.keyCode == 39) || (event.keyCode == 40)) { this.comboCompletionObject.searchPattern = ""; this.comboCompletionObject.updateInformationArea(); } return true; } this.keyDown = function() { if (event.keyCode == 8) { this.comboCompletionObject.searchPattern = this.comboCompletionObject.searchPattern.substring(0, this.comboCompletionObject.searchPattern.length - 1); this.comboCompletionObject.updateInformationArea(); this.comboCompletionObject.updateToFirstMatch(); return false; } return true; } this.blur = function() { this.comboCompletionObject.searchPattern = ""; this.comboCompletionObject.updateInformationArea(); if (typeof(this.comboCompletionObject.onChanged) == "function") { this.comboCompletionObject.onChanged(this); } } this.keyPress = function() { var key = String.fromCharCode(event.keyCode).toUpperCase(); if (/[a-zA-Z0-9\s.\/]/.test(key)) { this.comboCompletionObject.searchPattern += key; this.comboCompletionObject.updateInformationArea(); this.comboCompletionObject.updateToFirstMatch(); return false; } return true; } this.object.comboCompletionObject = this; this.object.onkeypress = this.keyPress; this.object.onkeyup = this.keyUp; this.object.onkeydown = this.keyDown; this.object.onblur = this.blur; } Abraços Carlos Jr
Gostei + 0
14/02/2009
Sergio Santos
Gostei + 0
14/02/2009
[devmedia .net]
Gostei + 0
16/02/2009
[devmedia .net]
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)