【发布时间】:2015-02-15 12:40:15
【问题描述】:
我想在 gridview 上进行 CLIENT-SIDE 数据搜索,以加快加载速度和提高性能(GV 上的数据正在由存储过程加载)
我已将此视为来源并尝试遵循代码但它不起作用。有什么问题? Filter records in gridview http://www.vonloesch.de/comment/reply/23
这就是我得到的
function filter2(phrase, _id) {
var words = phrase.value.toLowerCase().split(" ");
var table = document.getElementById(_id);
var ele;
for (var r = 1; r < table.rows.length; r++) {
ele = table.rows[r].innerHTML.replace(/<[^>]+>/g, "");
var displayStyle = 'none';
for (var i = 0; i < words.length; i++) {
if (ele.toLowerCase().indexOf(words[i]) >= 0)
displayStyle = '';
else {
displayStyle = 'none';
break;
}
}
table.rows[r].style.display = displayStyle;
}
}
<!-- A text box for entering search phrase and GridView1.ClientID returns the client id of gridview -->
<input name="txtTerm" onkeyup="filter2(this, '<%=grdLocation %>')" type="text">
<div class="ModalBodyGridview">
<asp:GridView ID="grdLocation" runat="server" AutoGenerateColumns="false" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource2" ForeColor="Black" GridLines="Vertical" Width="420px" OnSelectedIndexChanged="grdLocation_SelectedIndexChanged" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Location Num" HeaderText="Location Num" SortExpression="Location Num" />
<asp:BoundField DataField="Location Name" HeaderText="Location Name" SortExpression="Location Name" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="green" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RPSMSConnectionString %>" SelectCommand="spSearchLoc" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</div>
如果有人可以提出其他解决方案,我们将不胜感激。
【问题讨论】: