Wednesday, November 25, 2009

Filter Gridview on keypress of textbox in javascript

    <script type="text/javascript" charset="utf-8">
   
   function filter (term, _id, cellNr){
    var suche = term.value.toLowerCase();
    var table = document.getElementById(_id);
    var ele;
    for (var r = 1; r < table.rows.length; r++){
        ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
        if (ele.toLowerCase().indexOf(suche)>=0 )
            table.rows[r].style.display = '';
        else table.rows[r].style.display = 'none';
    }
}
</script>
  
     Filter:<input type="text" id="FilterTextBox" name="FilterTextBox" onkeyup="filter(this, 'filterable1', 0)"/>

              
                    <asp:GridView runat="server" ID="filterable1" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true">
                        <Columns>
                     
                            <asp:BoundField DataField="FirstName" HeaderText="Name" />
                            <asp:BoundField DataField="LastName" HeaderText="LastName" />
                        </Columns>
                    </asp:GridView>
Google