Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want client side searchable grid view. when i press any character in text box then grid view need to show data which is started from that character.
Thank u
Posted
Updated 8-May-16 19:03pm

<input type='text' onkeyup='Filter(this);'/>

function Fliter (Obj) {
    var grid=document.getElementById('gridID');
        var terms = Obj.value;
        var cellNr = this.filterCellIndex;//your  grid cellindex
        var ele;
        for (var r = 1; r < grid.rows.length; r++) {
            ele = grid.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
            if (ele.toLowerCase().indexOf(terms) >= 0)
                grid.rows[r].style.display = '';
            else grid.rows[r].style.display = 'none';
        }
    };
 
Share this answer
 
v2
Comments
Rajesh Anuhya 3-Feb-12 1:20am    
Edited: Code Tags added.
--RA
Nilesh Patil Kolhapur 3-Feb-12 1:43am    
Thanks Sanjay if u have any blog or facebook page give me link
Sanjay K. Gupta 3-Feb-12 2:05am    
My blog is
http://guptasanjay56.blogspot.com
AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox. Here is the property list:

XML
<ajaxToolkit:AutoCompleteExtender
    runat="server"
    ID="autoComplete1"
    TargetControlID="myTextBox"
    ServiceMethod="GetCompletionList"
    ServicePath="AutoComplete.asmx"
    MinimumPrefixLength="2"
    CompletionInterval="1000"
    EnableCaching="true"
    CompletionSetCount="20"
    CompletionListCssClass="autocomplete_completionListElement"
    CompletionListItemCssClass="autocomplete_listItem"
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
    DelimiterCharacters=";, :"
    ShowOnlyCurrentWordInCompletionListItem="true">
        <Animations>
            <OnShow> ... </OnShow>
            <OnHide> ... </OnHide>
        </Animations>
</ajaxToolkit:AutoCompleteExtender>
 
Share this answer
 
Comments
Nilesh Patil Kolhapur 3-Feb-12 1:07am    
what is service method and service path in it
After some modification in Sanjay K. Gupta's Code it will search the whole grid.


JavaScript
// Searching in whole grid
function Filter(txtbox, GridViewId) {
                var grid = document.getElementById(GridViewId);
                var terms = txtbox.value;
                var isExists = false;
                var ele;
                for (var r = 1; r &lt; grid.rows.length; r++) {
                    isExists = false;
                    for (var j = 0; j &lt; grid.rows[0].cells.length; j++) {
                        ele = grid.rows[r].cells[j].innerHTML;
                        if (ele.toLowerCase().indexOf(terms.toLowerCase()) &gt;= 0)
                            isExists = true;
                    }
                    if (!isExists)
                        grid.rows[r].style.display = 'none';
                    else
                        grid.rows[r].style.display = '';


            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900