【问题标题】:jquery function not working using Updatepanel in asp.netjquery函数在asp.net中使用Updatepanel不起作用
【发布时间】:2019-05-02 19:10:48
【问题描述】:

我正在使用文本框从 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>

【问题讨论】:

    标签: javascript jquery asp.net updatepanel


    【解决方案1】:

    使用 keydown 代替 keyup

    $(function () {
      $("[id*=txtspegqty]").keydown(function () {
        //calculate total for current row
        var val7 = $(this).val() == "" ? 0 : $(this).val();
      });
    });
    

    【讨论】:

      【解决方案2】:

      我相信您可以使用以下两个选项中的任何一个来解决此问题:

      选项 1

      asp:GridView元素上设置ClientIDMode="static"

      选项 2

      像这样更新 jquery 选择器代码:

      $("#<%=GridView1.ClientID%> tr td:nth-child(3)")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-15
        • 1970-01-01
        • 2014-08-03
        • 2011-01-08
        • 1970-01-01
        相关资源
        最近更新 更多