Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从JQuery向asp.net中继器添加行_Jquery_Asp.net_Ajax_Web Services_Repeater - Fatal编程技术网

如何从JQuery向asp.net中继器添加行

如何从JQuery向asp.net中继器添加行,jquery,asp.net,ajax,web-services,repeater,Jquery,Asp.net,Ajax,Web Services,Repeater,我的代码隐藏中有一个中继器,它已经有了一个列表,现在我在数据库表中添加了一个新行,该行保存中继器通过普通web服务在web表单上显示的数据,这很好 假设我的web服务方法向ajaxSuccess响应返回一个列表,那么如何使用新列表更新中继器,或者如何在ajaxSuccess方法中将新行添加到UI中。下面是方法 function UpdateUserServices(selectedService, userId) { $.ajax({ type: "POST",

我的代码隐藏中有一个中继器,它已经有了一个列表,现在我在数据库表中添加了一个新行,该行保存中继器通过普通web服务在web表单上显示的数据,这很好

假设我的web服务方法向ajaxSuccess响应返回一个列表,那么如何使用新列表更新中继器,或者如何在ajaxSuccess方法中将新行添加到UI中。下面是方法

function UpdateUserServices(selectedService, userId) {
$.ajax({
        type: "POST",
        url: "PresentationService.asmx/UpdateUserServices",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({'selectedService': selectedService,
        'userId': userId
    }),
    success: function(response) {
    //add new row to the asp.net repeater before closing dialog
        $(".dvAddServices").dialog("close");
    },
    error: function(response) {
        alert(response.d);
    }
});
}
像这样,

 success: function(response) {
var data = response.data;
var tC = new Array(); //TableContent
tC.push('<tr class="row" >');
tC.push('<td class="r">' + data.ID + '</td>');
tC.push('<td class="r">' + data.ID + '</td>');
tC.push('<td class="r">' + data.ID + '</td>');
tC.push("</tr>");
var html = '';
for (var i = 0; i < tC.length; i++) {
html += tC[i];
}
$(".table").append(html);
$(".dvAddServices").dialog("close");
}
成功:功能(响应){
var数据=响应数据;
var tC=new Array();//TableContent
tC.推力(“”);
tC.push(“”+data.ID+“”);
tC.push(“”+data.ID+“”);
tC.push(“”+data.ID+“”);
tC.推力(“”);
var html='';
对于(变量i=0;i
不使用数组的备选答案将是

success: function(response) {
var data = response.data;
      mytable = $('<table Class="table table-striped table-bordered table-hover"></table>').attr({ id: "basicTable" });
   var firstrow = $('<tr></tr>').appendTo(mytable);
            $('<td></td>').text('Entity Name').appendTo(firstrow);
            $('<td></td>').text('Attribute Name').appendTo(firstrow);
     $.each(data , function (i, obj) {
   var row = $('<tr></tr>').appendTo(mytable);
     $('<td valign="middle"></td>').text(obj.ID).appendTo(row);
  $('<td></td>').html("<div id='div1' >" + Obj.Name + "</div>").appendTo(row);
});
成功:功能(响应){
var数据=响应数据;
mytable=$('').attr({id:“基本表”});
var firstrow=$('').appendTo(mytable);
$('').text('Entity Name').appendTo(第一行);
$('').text('Attribute Name').appendTo(第一行);
$。每个(数据、功能(i、obj){
变量行=$('').appendTo(mytable);
$('').text(obj.ID).appendTo(行);
$(“”).html(“+Obj.Name+”).appendTo(行);
});

当数据下来时,它是包含所有的行还是只包含新的行?如果是所有的行,新的行是否被标记为新的行?将行添加到客户端的表中并不困难。主要问题是添加行后您打算做什么,因为当您回发到服务器时它不会持久。@mason哪是最好的方法,我认为只返回行是理想的,你为什么要问这个问题?这与添加到中继器的方式有关吗?@Win该行保存在数据库中,因此我需要它反映在UI中并保持在那里,除非我选择再次删除它。你有解决方案吗?只返回新行是最好的,因为数据库中已经存在的行已经存在您是否使用回发?如果不使用,那么应该非常简单,或者两个答案中的任何一个都有效。如果您