Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/02/2010, 09:57
darkmcloud
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Textbox dependiente con Ajax y ASP

Y este es el que realiza la consulta a la bd:

SelecUsuarios.asp:
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <%' Option Explicit %>
  3. <% Response.Buffer=True %>
  4. <% On Error Resume Next  %>
  5. <%Response.charset="utf-8"%>
  6. <%
  7. Response.addHeader "pragma", "no-cache"
  8. Response.CacheControl = "Private"
  9. Response.Expires = -1000
  10. %>
  11. <%
  12. Dim SQL, rs, oConn, registros, i
  13. Dim usuario
  14. Dim nombre
  15. nombre = 0
  16. Dim familia
  17. familia = ""
  18.  
  19. usuario = CStr(Request.QueryString("q"))
  20. combox = CStr(Request.QueryString("variable"))
  21. 'response.write ("'"&combox&"'")
  22.  
  23.  
  24. IF Len(usuario) >= 2 then
  25. ' CONEXIÓN
  26.  
  27.     set Cnn = Server.CreateObject("ADODB.Connection")
  28.     set rs = Server.CreateObject ("ADODB.Recordset")
  29.     Cnn.Open Session("cnx")
  30.  
  31. SQL="select descrip, familia from producto inner join familias on codi_fami = codi_familia "
  32.  
  33.     se_encuentra = False
  34.        
  35.      if combox = "constock" then
  36.             if se_encuentra then
  37.             SQL=SQL & " AND stock > 0"
  38.                 else
  39.             SQL=SQL & "WHERE stock > 0"
  40.             se_encuentra=True
  41.                   end if
  42.                 end if
  43.                    
  44.         if combox = "sinstock" then
  45.             if se_encuentra then
  46.             SQL=SQL & " AND stock = 0"
  47.                 else
  48.             SQL=SQL & "WHERE  stock = 0"
  49.           se_encuentra=True
  50.                   end if
  51.                     end if
  52.                    
  53.             if usuario <> "" then
  54.               if se_encuentra then
  55.     SQL=SQL & " AND descrip LIKE '"&usuario&"%'"
  56.         else
  57.         SQL=SQL & " WHERE descrip LIKE '"&usuario&"%'"
  58.           se_encuentra=True
  59.                      end if
  60.                      end if
  61.                    
  62.  
  63.  
  64. set rs = Cnn.Execute(SQL)
  65.         If not rs.eof then
  66.         registros = rs.getrows()
  67.         familia = rs.Fields("familia")
  68.             Else
  69.             Response.Write "<p class=""deseleccionado""><strong>Sin resultados</strong></p>"
  70.             Response.End ()
  71.         End If
  72.     rs.Close
  73.     set rs = nothing
  74.     Cnn.Close
  75.     set Cnn = nothing
  76. END IF
  77.  
  78. For i = 0 to Ubound(registros,2)
  79. If i = 0 then
  80. Response.Write "<div id="""& registros(nombre,i) &""" class=""seleccionado"">"& ResaltarSubStr(registros(nombre,i)) & "</div>"
  81. Else
  82. Response.Write "<div id="""& registros(nombre,i) &""" class="""">" & ResaltarSubStr(registros(nombre,i)) & "</div>"
  83. End If
  84. Next
  85.  
  86. Response.Write "-" & familia
  87.  
  88. ' ========= Funciones ===========
  89. Function ResaltarSubStr(texto)
  90. Dim objRegExp
  91.  
  92.     Set objRegExp= New RegExp
  93. objRegExp.IgnoreCase = True
  94. 'objRegExp.Global = True
  95.  
  96. objRegExp.Pattern = "\b("&usuario&")+(\w)"
  97. texto = objRegExp.Replace(texto, "<strong>$1</strong>$2")
  98.  
  99.     Set objRegExp = Nothing
  100.  
  101.     ResaltarSubStr = texto
  102.  
  103. End Function
  104. ' ========= Fin Funciones ===========
  105. %>

Eso seria.....
De antemano muchas gracias.
Hasta pronto