我有一个将数据从 webmethod 附加到 gridview 的 js 文件。我的问题是,每当我再次单击我的按钮时,它都会在 gridview 中使用以前的数据附加并添加新数据。有没有办法删除最后附加的数据并附加一个新数据?另一个问题。在绑定网格视图时,我需要在加载页面时绑定数据源,以便让它显示我想要附加的数据。如何删除尝试附加新数据源时绑定的数据源?对不起,很长很长的问题。谢谢!
$.ajax({
url: "Default.aspx/getDetails",
data: Data,
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (mydata) {
for (var i = 0; i < mydata.d.length; i++) {
$(".rpt").html("<table id=\"tbl\"><tr>" +
"<th style='background-color: #75a844' class='tbl_h'>Date Joined</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Memberid</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Member ID</th>" +
"<th style='background-color: #75a844' class='tbl_h'>User ID</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Username</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Password</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Full Name</th>" +
"<th style='background-color: #75a844' class='tbl_h'>First Name</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Last Name</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Birth Date</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Address</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Location</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Sponsor ID</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Parent ID</th>" +
"<th style='background-color: #75a844' class='tbl_h'>Placement</th>" +
"</tr>");
for (var i = 0; i < mydata.d.length; i++) {
$("#tbl").append("<tr><td>" + mydata.d[i].datejoined +
"</td><td>" + mydata.d[i].memid +
"</td><td>" + mydata.d[i].memberid +
"</td><td>" + mydata.d[i].userid +
"</td><td>" + mydata.d[i].usrname +
"</td><td>" + mydata.d[i].pssword +
"</td><td>" + mydata.d[i].fullname +
"</td><td>" + mydata.d[i].fname +
"</td><td>" + mydata.d[i].mname +
"</td><td>" + mydata.d[i].lname +
"</td><td>" + mydata.d[i].bdate +
"</td><td>" + mydata.d[i].address +
"</td><td>" + mydata.d[i].location +
"</td><td>" + mydata.d[i].sponsorid +
"</td><td>" + mydata.d[i].parentid +
"</td><td>" + mydata.d[i].placement + "</td></tr>");
}
$("#tbl").append("</table>");
}
});