2012-03-03 37 views
10

¿Cómo puedo resaltar el texto de una consulta en el control gridview?¿Cómo puedo resaltar una palabra en gridview

+0

Si bien el código, obviamente, no será el mismo, escribí un artículo rápido hace varios años destacando (sin doble sentido) el enfoque básico: http: //classicasp.aspfaq.com/general/how-do-i-highlight-words-in-a-string.html –

+0

Dado que esto puede implicar un poco de código para lograr, eche un vistazo a: - http: // evonet .com.au/gridview-with-highlighted-search-results/ – skub

+0

Esto explica cómo: http://forums.asp.net/t/1109807.aspx/1?Highlighting+result+in+GridView –

Respuesta

2

si quieres hacer esto lado del cliente por favor seguir los siguientes pasos:

añadir referencia jQuery para su Pagina.add una entrada de texto Calles txt_Search.

y luego usar este script:

$(document).ready(function() { 
      $('#txt_Search').keyup(function() { 
       searchTable($(this).val()); 
      }); 

      function searchTable(inputVal) { 
       var table = $('#GridView1'); 
       table.find('tr').each(function (index, row) { 
        var allCells = $(row).find('td'); 
        if (allCells.length > 0) { 
         var found = false; 
         allCells.each(
      function (index, td) { 
       var regExp = new RegExp(inputVal, 'i'); 
       if (regExp.test($(td).text())) { 
        found = true; 
        return false; 
       }}); 
         if (found == true) $(row).show(); else $(row).hide(); 
        } 
       }); 
      } 
     }); 
-4

buscar el texto, vestir con una etiqueta como <label>, y no te olvides de agregar estilo de resaltado para las etiquetas.

+0

No lo hago entender –

0
var gv = document.getElementById("#GridView1"); 

    for (var i = 0; i < gv.all.length; i++) { 
var cellValue = grid.rows[i].cells[0].elements[0]; 
cellValuestyle.background = '#DD00DD'; 
} 
Cuestiones relacionadas