This function works. It's a quick way of selecting all the checkboxes in a GridView from the checked status of the header checkbox, and for only a specific column.
//jQuery to select all checkboxes on the last column (4th column) of gvStudents
function SelectAllCheckboxesCol(chk)
{
//var gV = chk.parent;
var wsList = "#<%=gvStudents.ClientID %> >tbody >tr >td:nth-child(4) > input:checkbox";
var cBox = $(wsList);
cBox.attr('checked', chk.checked); //check all the checkboxes
}
I don't like hard-coding in the gvStudents nor the column number 4.
How can I re-write this to be more dynamic - ie: to bring in the Gridview and n-th column number?
Here was my attempt but I get literal and no object reference errors.
//jQuery to select all checkboxes on the last column (4th column) of gvStudents
function SelectAllCheckboxesCol(chk)
{
var gV = chk.parent; // assume this brings in the Gridview?
var wsList = "#<%=" + gV.CliendID + " %> >tbody >tr >td:nth-child(4) > input:checkbox";
var cBox = $(wsList);
cBox.attr('checked', chk.checked); //check all the checkboxes
}
Thanks
Aucun commentaire:
Enregistrer un commentaire