Foros del Web » Programación para mayores de 30 ;) » .NET »

Según va escribiendo que muestre los resultados

Estas en el tema de Según va escribiendo que muestre los resultados en el foro de .NET en Foros del Web. Hola Quiero hacer una página en vb.net que contiene un apartado de búsqueda y una tabla de usuarios. Al cargar la pagina habrá un apartado ...
  #1 (permalink)  
Antiguo 19/04/2013, 06:00
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Según va escribiendo que muestre los resultados

Hola
Quiero hacer una página en vb.net que contiene un apartado de búsqueda y una tabla de usuarios.

Al cargar la pagina habrá un apartado de búsqueda y automáticamente mediante un select se se cargara la tabla con dos columnas, en la primera el numero de empleado y en la segunda el nombre de este.

La función del apartado de búsqueda, me gustaría que fuese que según va escribiendo un usuario que utilice esta aplicación una palabra o letra en el apartado de búsqueda, la tabla vaya cambiando dependiendo de lo que se vaya introduciendo en el textbox de búsqueda.

¿Cómo puedo hacer esto? ¿Alguien me puede ayudar?

__________________
Gracias por todo;

Un saludo
  #2 (permalink)  
Antiguo 20/04/2013, 21:07
Avatar de othix  
Fecha de Ingreso: mayo-2011
Ubicación: Guatemala
Mensajes: 92
Antigüedad: 13 años
Puntos: 9
Respuesta: Según va escribiendo que muestre los resultados

Con ajax control toolkit

http://www.asp.net/ajaxlibrary/act_A...te_simple.ashx

http://www.asp.net/ajaxLibrary/AjaxC...oComplete.aspx
__________________
"Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas."
  #3 (permalink)  
Antiguo 22/04/2013, 02:01
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Respuesta: Según va escribiendo que muestre los resultados


Nunca he utilizado ajax y me gustaría aprender a programar con ello. Voy a echarle un vistacillo a lo que has mandado.

Gracias
__________________
Gracias por todo;

Un saludo
  #4 (permalink)  
Antiguo 23/04/2013, 02:32
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Exclamación Respuesta: Según va escribiendo que muestre los resultados

Hola;

He estado mirando y la verdad es que no me aclaro mucho. He echo lo siguiente y no se si esta bien echo ya que le doy al botón buscar que he declarado y donde supuesta-mente quiero hacer lo que tiene que hacer con AJAX y no me hace nada.

Pongo mi código para que me echéis una mano:
Código ASP:
Ver original
  1. <%@ Page Title="Página Principal" Language="vb"  MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="Principal.aspx.vb" Inherits="HorasOperarios.Principal" %>
  2.  
  3. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  4. </asp:Content>
  5. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  6.     <div id="busqueda">
  7.         <asp:Table ID="TableBuscar" runat="server" BorderColor="Gray" CellPadding="2" CellSpacing="5"  Width="300px" align="center">  
  8.             <asp:TableRow Font-Bold="True" Font-Overline="False">
  9.                 <asp:TableCell ID="TableCellBuscar1" HorizontalAlign="Left" Enabled="True" Width="300px">
  10.                     <asp:Label ID="LabelBuscar1" runat="server" Text="Introduzca el nombre del operario:" aling="center"></asp:Label><br />
  11.                 </asp:TableCell>
  12.             </asp:TableRow>
  13.             <asp:TableRow>
  14.                 <asp:TableCell ID="TableCellBuscar2" HorizontalAlign="Left" Enabled="True" Width="250px">
  15.                     <asp:TextBox ID="TextNombreBuscar" runat="server" aling="Left" Width="250px"></asp:TextBox>                    
  16.                     <asp:Label ID="LabelAsterisco1" runat="server" aling="center"></asp:Label><br />
  17.                 </asp:TableCell>                
  18.                 <asp:TableCell ID="TableCellBuscar3" HorizontalAlign="Left" Enabled="True" Width="50px">
  19.                     <input id="btnBuscar" type="button" value="BUSCAR"  onclick="javascript:Principal.obtener_operarios(TextNombreBuscar.value, obtener_operarios_CallBack)"/>
  20.                 </asp:TableCell>
  21.             </asp:TableRow>
  22.         </asp:Table>      
  23.     </div>
  24.     <div id="tabla2">
  25.         <asp:Table ID="Table2" runat="server" BorderColor="Gray" CellPadding="2" CellSpacing="5"  Width="500px" align="center">  
  26.             <asp:TableRow Font-Bold="True" Font-Overline="False">
  27.                 <asp:TableCell ID="Table2Cell1" HorizontalAlign="Left" Enabled="True" Width="100px" BorderStyle="Solid">
  28.                     <asp:Label ID="LabelCell1" runat="server" Text="NºOPERARIO" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label>
  29.                 </asp:TableCell>
  30.                 <asp:TableCell ID="Table2Cell2" HorizontalAlign="Left" Enabled="True" Width="300px" BorderStyle="Solid">
  31.                     <asp:Label ID="LabelCell2" runat="server" Text="OPERARIO" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label>
  32.                 </asp:TableCell>
  33.                 <asp:TableCell ID="Table2Cell3" HorizontalAlign="Left" Enabled="True" Width="100px" BorderStyle="Solid">
  34.                     <asp:Label ID="LabelCell3" runat="server" Text="VER" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label>
  35.                 </asp:TableCell>
  36.                 <asp:TableCell ID="TableCell4" HorizontalAlign="Left" Enabled="True" Width="100px" BorderStyle="Solid" Visible="false">
  37.                     <asp:Label ID="LabelCell4" runat="server" Text="Numope" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium" visible="false"></asp:Label>
  38.                 </asp:TableCell>
  39.             </asp:TableRow>
  40.         </asp:Table>  
  41.     </div>
  42.  
  43.     <script type="text/javascript">
  44.         function obtener_operarios_CallBack(response) {
  45.  
  46.             if (response.error != null) {
  47.                 alert("Se presentó un error ");
  48.                 return;
  49.             }
  50.             target = "TextNombreBuscar";
  51.             document.getElementById(target).innerHTML = response.value;
  52.         }
  53.         </script>
  54. </asp:Content>

Código vb.net:
Ver original
  1. Imports MySql.Data.MySqlClient
  2. Imports System.Configuration
  3. Imports Oracle.ManagedDataAccess.Client
  4. Imports Oracle.ManagedDataAccess.Types
  5. <AjaxPro.AjaxNamespace("Principal")> _
  6. Public Class Principal
  7.     Inherits System.Web.UI.Page
  8.  
  9.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  10.         'Register Ajax.NET methods from this class
  11.         AjaxPro.Utility.RegisterTypeForAjax(GetType(Principal))
  12.         Dim textBuscar As New TextBox()
  13.         Dim conn As New MySqlConnection
  14.         'se apunta a la cadena de conexion guardada en el archivo Web.config
  15.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  16.         Dim mysql_comando As New MySqlCommand("select distinct noperario, operario from cdp_operaciones order by operario asc", conn)
  17.         Dim reader As MySqlDataReader
  18.         Dim da As New MySqlDataAdapter(mysql_comando)
  19.         Dim objRow As New TableRow()
  20.         Dim numoperario, nombre As String
  21.  
  22.         Try
  23.  
  24.             Using conn
  25.                 'se abre la conexion
  26.                 conn.Open()
  27.  
  28.                 With mysql_comando
  29.                     reader = .ExecuteReader()
  30.                     While reader.Read()
  31.  
  32.                         objRow = New TableRow()
  33.                         Dim objCell1, objCell2, objCell3, objCell4 As New TableCell()
  34.                         Dim linkDetalle, linkMes As New HyperLink()
  35.  
  36.                         numoperario = reader.GetValue(0)
  37.                         nombre = reader.GetValue(1)
  38.  
  39.                         objCell1.Controls.Add(New LiteralControl(numoperario))
  40.                         objCell1.HorizontalAlign = HorizontalAlign.Center
  41.                         objCell2.Controls.Add(New LiteralControl(nombre))
  42.                         objCell2.HorizontalAlign = HorizontalAlign.Left
  43.                         linkDetalle.Text = "Detalle"
  44.                         linkDetalle.NavigateUrl = "~/HorasOperarios.aspx"
  45.                         objCell3.Controls.Add(New LiteralControl(linkDetalle.Text))
  46.  
  47.                         objCell4.Controls.Add(New LiteralControl(numoperario))
  48.                         objCell4.Visible = False
  49.                         objRow.Cells.Add(objCell1)
  50.                         objRow.Cells.Add(objCell2)
  51.                         objRow.Cells.Add(objCell3)
  52.                         'objRow.Cells.Add(objCell4)
  53.                         Table2.Rows.Add(objRow)
  54.                     End While
  55.                     .Dispose()
  56.                 End With
  57.             End Using
  58.         Catch ex As Exception
  59.  
  60.             MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  61.             'mensaje("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  62.         Finally
  63.             conn.Close()
  64.             conn.Dispose()
  65.         End Try
  66.     End Sub
  67.  
  68.     <AjaxPro.AjaxMethod()> _
  69.     Public Function obtener_operarios(ByVal nombre As String) As String
  70.  
  71.         Dim conn As New MySqlConnection
  72.         Dim nombreBuscar As String
  73.         'se apunta a la cadena de conexion guardada en el archivo Web.config
  74.         nombreBuscar = UCase(nombre)
  75.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  76.         Dim mysql_comando As New MySqlCommand("select distinct noperario, operario from cdp_operaciones where operario like '%" & nombreBuscar & "%'order by operario asc", conn)
  77.         Dim reader As MySqlDataReader
  78.         Dim da As New MySqlDataAdapter(mysql_comando)
  79.         Dim objRow As New TableRow()
  80.         Dim numoperario, nombreoperario As String
  81.  
  82.         Try
  83.             Using conn
  84.                 'se abre la conexion
  85.                 conn.Open()
  86.  
  87.                 With mysql_comando
  88.                     reader = .ExecuteReader()
  89.                     While reader.Read()
  90.  
  91.                         objRow = New TableRow
  92.                         Dim objCell1, objCell2 As New TableCell()
  93.  
  94.                         numoperario = reader.GetValue(0)
  95.                         nombreoperario = reader.GetValue(1)
  96.  
  97.                         objCell1.Controls.Add(New LiteralControl(numoperario))
  98.                         objCell1.HorizontalAlign = HorizontalAlign.Center
  99.                         objCell2.Controls.Add(New LiteralControl(nombreoperario))
  100.                         objCell2.HorizontalAlign = HorizontalAlign.Left
  101.                         objRow.Cells.Add(objCell1)
  102.                         objRow.Cells.Add(objCell2)
  103.                         Table2.Rows.Add(objRow)
  104.                     End While
  105.                     .Dispose()
  106.                 End With
  107.             End Using
  108.             'Return FormatNumber(CDec(valor1) + CDec(valor2) + CDec(valor3), 2)
  109.         Catch ex As Exception
  110.             Return "0"
  111.         Finally
  112.             conn.Close()
  113.             conn.Dispose()
  114.         End Try
  115.     End Function
  116. End Class

__________________
Gracias por todo;

Un saludo

Etiquetas: resultados, según, tabla, vb
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:39.