Bhavleen Singh

Bhavleen Singh

  • NA
  • 203
  • 5k

GridView validation using JQuery

Jul 1 2019 1:37 AM
Here I've 2 columns containing checkboxes, for selecting that I'm using JQuery mention as follows
 
$("[id*=Bankcb]").live("click", function () {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[id*=BankApprovecb]", grid).each(function () {
if (chkHeader.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=BankApprovecb]").live("click", function () {
var grid = $(this).closest("table");
var chkHeader = $("[id*=Bankcb]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkHeader.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=BankApprovecb]", grid).length == $("[id*=BankApprovecb]:checked", grid).length) {
chkHeader.attr("checked", "checked");
}
}
});
$("[id*=TReDScb]").live("click", function () {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[id*=TReDS_Statuscb]", grid).each(function () {
if (chkHeader.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=TReDS_Statuscb]").live("click", function () {
var grid = $(this).closest("table");
var chkHeader = $("[id*=TReDScb]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkHeader.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=TReDS_Statuscb]", grid).length == $("[id*=TReDS_Statuscb]:checked", grid).length) {
chkHeader.attr("checked", "checked");
}
}
});
 
but I've 1 validation, that if columns of 1st checkboxes is checked then user couldn't check the checkboxes given on 2nd column followed by alert message, I'm not able to get exact logic to do this. Can Anyone Help me on this. 

Answers (2)