0

这是场景,当单击搜索按钮时,将 GridView 控件的内容附加到 html 表 data(td) 中,从 WebMethod 加载 html 表的数据。问题是,当每次单击搜索按钮时,GridView 都会附加具有同一行记录的表数据,有什么办法可以避免这种情况?

jQuery

    $("#dialog_link").click(function (e) {
        e.preventDefault();               
        $.ajax({  
            type: "POST",
            url: "CustomerSearch.aspx/SearchCustomer",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ value: $("#search_key").val() }),
            dataType: "json",
            async: true,                   
            success: function (data, status) { 
                var table;
                console.log(data);                       
                for (var i = 0; i < data.d.length; i++) {
                    table += "<tr><td class='key' style='display:none'>" + data.d[i].custid + "</td>" +
                                    "<td><a class='custlink' style='text-decoration:none' href=#>" + data.d[i].custname + "</a></td>" +
                                    "<td>" + data.d[i].mobno + "</td>" +
                                    "<td>" + data.d[i].email + "</td></tr>";
                }
                $("#gvCustomer").append(table);                        
            },
            error: function (data, status, error) {
                //console.log(error)
            },
        });

HTML

 <div id="search_result" style="margin-top:10px">
     <asp:GridView ID="gvCustomer" runat="server" Width="100%"></asp:GridView>
 </div >
4

0 回答 0