【发布时间】:2016-07-13 05:46:59
【问题描述】:
这是我的激活所有按钮的 c# 代码:
[WebMethod]
public static void ActivateSelected(String Id)
{
clsCategoryBL objproject = new clsCategoryBL();
string[] arr = Id.Split(',');
string strid = arr[2];
foreach (var id in arr)
{
if (!string.IsNullOrEmpty(id))
{
objproject.CategoryStatus(Convert.ToInt32(strid), true);
}
}
BindDatatable();
}
这是我的 jquery 表绑定代码:
function ActivateSelected() {
var ids = '';
var cells = Array.prototype.slice.call(document.getElementById("example1").getElementsByTagName('td'));
debugger;
for (var i in cells) {
var inputArray = cells[i].getElementsByTagName('input');
for (var i = 0; i < inputArray.length; i++) {
if (inputArray[i].type == 'checkbox' && inputArray[i].checked == true) {
debugger;
ids += inputArray[i].id + ',';
}
}
}
debugger;
var urldata = "Category.aspx/ActivateSelected";
$.ajax(
{
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
url: urldata,
data: "{Id:'" + ids + "'}",
success: function (dt) {
debugger;
location.reload();
$("#example1").DataTable();
//$("#example1").bind;
debugger;
},
error: function (result) {
alert("Error");
//console.log();
//alert(result);
}
});
}
The problem is that when select all the checkbox and click on Activate all button only First row status is activate instead of All row status,So kindly help me out. 这是我的全部激活按钮:
<i class="fa fa-check-square-o" name="activatebtn" onclick='ActivateSelected();' style='font-size:22px;margin-left: 32px;color:green'>Activate Selected</i>
这是选中所有复选框的代码:
function Selectallcheckbox() {
var cells = Array.prototype.slice.call(document.getElementById("example1").getElementsByTagName('td'));
var check = document.getElementById('chkall');
if (check.checked) {
for (var i in cells) {
var inputArray = cells[i].getElementsByClassName('chk');
for (var i = 0; i < inputArray.length; i++) {
inputArray[i].checked = true;
}
}
}
else {
for (var i in cells) {
var inputArray = cells[i].getElementsByClassName('chk');
for (var i = 0; i < inputArray.length; i++) {
inputArray[i].checked = false;
}
}
}
}
我认为问题出在这里(c#):
string strid = arr[2];
在 strid 中只有一个 id..并且只有一个 id 绑定
objproject.CategoryStatus(Convert.ToInt32(strid), true);
如果我在上面的行中使用 Id 而不是 strid,由于最后一个逗号..输入字符串的格式不正确,它会为我提供错误..
【问题讨论】:
-
是否所有的 id 都进入了 Web Method
ActivateSelected()。在 webmethod 上放置一个断点并检查传递给它的Id。 -
是的....所有的 id 都来了@AshleyJohn
-
然后把这一行编辑成
objproject.CategoryStatus(Convert.ToInt32(id), true);我已经把foreach循环变量strid改成了id。 -
输入字符串格式不正确..错误来了..@AshleyJohn...我想由于最后一个逗号..我该如何处理
-
你能告诉我正在传递给 WebMethod 的
Id