JS搜索功能不会在每个页面上搜索数据

时间:2017-07-05 21:28:19

标签: javascript asp.net gridview pagination

我正在尝试使用分页从gridview中搜索记录,与输入到文本框中的值匹配,并且它的工作非常好。问题是它只显示第一页的记录,但不会搜索下一页的记录。

这是我的JS。代码

<script type="text/javascript">
    function Search_Gridview(strKey, strGV) {
        var strGV = '<%= GridView1.ClientID %>';
        var strData = strKey.value.toLowerCase().split(" ");
        var tblData = document.getElementById(strGV);
        var rowData;

        for (var i = 1; i < tblData.rows.length; i++) {
            rowData = tblData.rows[i].innerHTML;
            var styleDisplay = 'none';
            for (var j = 0; j < strData.length; j++) {
                if (rowData.toLowerCase().indexOf(strData[j]) >= 0)
                    styleDisplay = '';
                else {
                    styleDisplay = 'none';
                    break;
                }
            }
            tblData.rows[i].style.display = styleDisplay;
       }
   }
</script>

和我的gridview

<asp:TextBox ID="txtSearch" runat="server" Font-Size="20px" onkeyup="Search_Gridview(this, 'gvTest')"></asp:TextBox><br />
<div class="rounded-corners">
  <div style="width: 100%; overflow: auto;">
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="False" AutoGenerateColumns="False" DataKeyNames="POS ID" GridLines="Horizontal" BorderColor="#ECF0F1" BorderRadius="15px" AlternatingRowStyle-BackColor="#F2F3F4" RowStyle-Wrap="false"
      HeaderStyle-Wrap="false" RowStyle-BorderColor="#e8e8ec" CssClass="gridviewdesign " RowStyle-CssClass="GV" OnSelectedIndexChanged="GridView1_OnSelectedIndexChanged" OnRowCommand="GridView1_OnRowCommand" OnRowDeleting="GridView1_OnRowDeleting" OnPageIndexChanging="GridView1_OnPageIndexChanging"
      EmptyDataText="No point of sales to display">
      <Columns>
        <asp:CommandField HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" ButtonType="Image" HeaderText="Actions" DeleteImageUrl="~/assets/global/img/deletee.png" SelectImageUrl="~/assets/global/img/edit.png" ShowDeleteButton="True" ShowHeader="True"
          ShowSelectButton="True" />
        <asp:BoundField DataField="POS ID" HtmlEncode="False" HeaderText="POS ID" ReadOnly="True" SortExpression="POS ID" HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" />
        <asp:BoundField DataField="Name" HtmlEncode="False" HeaderText="Name" SortExpression="Name" HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" />
        <asp:BoundField DataField="Country" HtmlEncode="False" HeaderText="Country" SortExpression="Country" HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" />
        <asp:BoundField DataField="City" HtmlEncode="False" HeaderText="City" SortExpression="City" HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" />
        <asp:BoundField DataField="Address" HtmlEncode="False" HeaderText="Address" SortExpression="Address" HeaderStyle-CssClass="gridView1" ItemStyle-CssClass="gridviewBody" />

      </Columns>
      <PagerStyle CssClass="pagination-ys" />
    </asp:GridView>
  </div>
</div>

0 个答案:

没有答案