我有一個網格,其中每個行都添加了複選框。當我點擊刪除按鈕而不點擊複選框時,它會顯示「請至少選擇一行來執行」。點擊複選框時也會顯示相同的信息。請幫助我找出解決方案和我在下面提到的代碼中所犯的錯誤。刪除函數點擊jquery中的複選框傳遞ID
//Calling Delete function clicking on checkbox
$(document).ready(function() {
//Grid Function
$.ajax(
{
url: "GetCompanyTypeMasterDetails",
type: "get",
dataType: "json",
contentType: "application/json",
success: function (data) {
$("#grid").igGrid({
autoGenerateColumns: false,
primaryKey: "CompanyTypeID",
columns: [
{ headerText: "Company Type ID", key: "CompanyTypeID", dataType: "Numeric", hidden: true },
{
headerText: "", key: "CompanyTypeID", dataType: "Numeric", width: "80",
template: '<table><tr><td><input type="image" src="/Images/GridImages/edit.png" onclick = "EditRecords(${CompanyTypeID})" /></td><td><input type="image" src="/Images/GridImages/delete.png" onclick = "DeleteRecords(${CompanyTypeID})" /></td></tr></table>'
},
{ headerText: "", key:"CompanyTypeID", dataType:"Numeric", width:"50", template: '<input type="checkbox" id="chkID" />'},
{ headerText: "Company Type", key: "CompanyTypeName", dataType: "string", width: "600" },
{ headerText: "Company Code", key: "Code", dataType: "string", width: "600" },
dataSource: data}
});
$("#btnDelete").click(function (ID) {
var isSelected = $('#chkID').is(':checked');
if (!isSelected) {
alert("Please select atleast one row to perform this action");
}
else if (isSelected) {
DeleteRecords(ID);
}
});
});
});
//Delete Function
function DeleteRecords(ID) {
$.ajax(
{
url: "DeleteRecords",
type: "post",
dataType: "json",
data: {CompanyTypeID : ID},
success: function (data) {
alert("Are you sure you want to Delete?");
location.reload();
},
error: function (status) {
alert(status.responseText);
}
});
}
您正在使用相同的ID爲每個刪除按鈕,複選框,使用不同的ID或使用類。 – 2014-09-04 06:17:38
向我們展示瞭如何將行添加到網格。 – 2014-09-04 06:18:21
你想要一個確切的問題的解決方案? – Leo 2014-09-04 06:28:51