我怎样才能遍历网格视图的所有单元格?

时间:2013-05-25 07:22:10

标签: javascript asp.net jquery gridview

我的aspx页面上有网格视图,如果用户输入我表格中的数据,我会在网格视图上方显示文本框。我想遍历我的网格的每个单元格并检查值是否相同显示它,如果不隐藏它。现在我有一个代码,它只能通过一列来完成这项工作,它遍历一列中的所有行。我想改变这个代码,我可以遍历所有列和它的所有行。如果有人知道请帮助我

  $(document).ready(function () {
            //
            // Client Side Search (Autocomplete)
            // Get the search Key from the TextBox
            // Iterate through the 1st Column.
            // td:nth-child(1) - Filters only the 1st Column
            // If there is a match show the row [$(this).parent() gives the Row]
            // Else hide the row [$(this).parent() gives the Row]

            $('#filter').keyup(function (event) {
                var searchKey = $(this).val();
                var a = $('#gvwHuman_ctl00');
                var b = a.attr.length;

              $("#gvwHuman_ctl00 tr td:nth-child("2")").each(function () {
                    var cellText = $(this).text();
                    if (cellText.indexOf(searchKey) >= 0) {
                        $(this).parent().show();
                    }
                    else {
                        $(this).parent().hide();
                    }

                });

            });
        }); 

和我的表结构我使用rad grid Telerik组件,但它与网格视图相同

 <table id="gvwHuman_ctl00" class="rgMasterTable rgClipCells" border="0" style="width:100%;table-layout:fixed;overflow:hidden;empty-cells:show;">
    <colgroup>
    <thead>
    <tr>
    <th class="rgResizeCol rgHeader" scope="col"> </th>
    <th class="rgHeader" scope="col" title="Drag to group or reorder" style="cursor: move;">کد</th>
    <th class="rgHeader" scope="col">
    <a href="javascript:__doPostBack('gvwHuman$ctl00$ctl02$ctl01$ctl00','')" title="Click here to sort">نام</a>
    </th>
    <th class="rgHeader" scope="col">
    <a href="javascript:__doPostBack('gvwHuman$ctl00$ctl02$ctl01$ctl01','')" title="Click here to sort">هزینه</a>
    </th>
    </tr>
    <tr class="rgFilterRow" style="font-family: Tahoma; display: none;">
    </thead>
    <tfoot>
    <tr class="rgPager" valign="middle" style="font-family: Tahoma;">
    <td colspan="4">
    <table border="0" style="width:100%;border-spacing:0;" summary="Data pager which controls on which page is the RadGrid control.">
    <caption>
    <thead>
    <tbody>
    <tr>
    <td class="rgPagerCell NextPrevAndNumeric">
    <div class="rgWrap rgArrPart1">
    <div class="rgWrap rgNumPart">
    <div class="rgWrap rgArrPart2">
    <div class="rgWrap rgAdvPart">
    <span id="gvwHuman_ctl00_ctl03_ctl01_ChangePageSizeLabel" class="rgPagerLabel">سایز صفحه</span>
    <div id="gvwHuman_ctl00_ctl03_ctl01_PageSizeComboBox" class="RadComboBox RadComboBox_WebBlue RadComboBox_rtl RadComboBox_WebBlue_rtl" style="width:46px;">
    </div>
    </td>
    </tr>
    </tbody>
    </table>
    </td>
    </tr>
    </tfoot>
    <tbody>
    </table>

0 个答案:

没有答案