asp.net中继器自动设置索引

asp.net Repeater auto set index

我是 asp.net 的新手,现在使用控件 asp:Repeater。 我想通过 Repeater 实现 follow table:

            index             Name           Delete

              1               DDD              X

              2               EEE              X

              3               FFF              X

现在索引由 asp.net 页中的设置 <%# (Container.ItemIndex+1) %> 自动生成。

我的问题如下:

当我点击'X'通过JS方法删除TableRow时。如何让列索引值刷新?但遗憾的是,列 idx 变为以下:

              index           Name           Delete

              1               DDD              X

              3               FFF              X

提前致谢。

因为您要通过 javascript 删除它。只需连接到它并添加一段代码来重新播种您的索引

// sample reseeding code
$('button').on('click', function() {

    $(this).closest('tr').remove();

    $('table').find('tbody').find('tr').each(function(i) {
        // update the value of the index column
        $(this).find('td').first().text(i + 1);
    });
});

演示: http://jsfiddle.net/7fbnn95a/

when I click 'X' to remove TableRow by register Js method

如果是 JS,那么你就没有 C# 代码了。

因此您的问题也应标记为 JS/jQuery。

关于:

How to make the column index value refresh ?

我使用 jQuery 的解决方案是:

$("#t tr td:nth-child(1)").on('click',function (i,n){ 
  $(this).closest('tr').remove();

    $("#t tr td:nth-child(1)").each(function (i,n){$(this).text(i+1)})                         

})

http://jsbin.com/hutefo/3/edit