我使用文本框从gridview搜索记录,没有更新面板,搜索工作正常,但当我使用更新面板时,它没有。
使用Javascript
$(document).ready(function () {
$('#txtSearchbox').keyup(function (event) {
event.preventDefault();
var searchKey = $('#txtSearchbox').val();
$("#GridView1 tr td:nth-child(3)").each(function () {
var cellText = $(this).text().toLowerCase();
if (cellText.indexOf(searchKey) >= 0) {
$(this).parent().show();
}
else {
$(this).parent().hide();
}
});
});
});
格
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<input type="text" id="txtSearchbox"/>
<input type="button" id="btnsearch" value="Search"/>
<asp:Panel ID="Panel1" ScrollBars="Vertical" Height="500px" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="true"
Width="100%"
BorderColor="#DEDFDE" BorderStyle="Ridge" BorderWidth="1px" CellPadding="4"
Font-Size="Small" ForeColor="Black" GridLines="Vertical"
OnRowDataBound="GridView1_RowDataBound" OnDataBound="OnDataBound"
CssClass="table table-responsive table-striped table-hover" EmptyDataText="No Record Found..."
RowStyle-Height="7px">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
HeaderStyle-Width="40px">
<asp:boundfield datafield="OrderID" headertext="OrderID"/>
<%--
<asp:CommandField ShowEditButton="True" ItemStyle-HorizontalAlign="Center"/>
<asp:CommandField ShowDeleteButton="True" ItemStyle-HorizontalAlign="Center"/>
--%>
</Columns>
<EmptyDataRowStyle Width="1195px" HorizontalAlign="Center" BackColor="#C2D69B"/>
<RowStyle BackColor="#F7F7DE"/>
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White"/>
<HeaderStyle Height="10px" VerticalAlign="Middle" BackColor="#6B696B" CssClass="tb_font"
ForeColor="White"/>
<AlternatingRowStyle BackColor="White"/>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
我相信您可以使用以下两个选项中的任何一个来解决此问题:
选项1
在ClientIDMode="static"
元素上设置asp:GridView
选项2
像这样更新jquery选择器代码:
$("#<%=GridView1.ClientID%> tr td:nth-child(3)")