skamranj
03-07-2011, 12:13 PM
Hi Everyone,
I have a gridview control with a checkbox control in each row of data.
based on some database value some of the rows in the gridview have a Blue background color.
I need a button using javascript to TICK the checkbox in the all the rows where the background color of the row is BLUE.
is it possible to modify the following Javascript to do the required function on a button click.
// toggle state of the checkbox between selected and not selected!
function toggleCheckBoxes(gvId, isChecked)
{
var checkboxes = getCheckBoxesFrom(document.getElementById(gvId));
for (i = 0; i <= checkboxes.length - 1; i++)
{
checkboxes[i].checked = isChecked;
}
}
// get all the checkboxes from the container control
function getCheckBoxesFrom(gv)
{
var checkboxesArray = new Array();
var inputElements = gv.getElementsByTagName("input");
//var inputElements = gv.getElementsById("chkAll");
if (inputElements.length == 0) null;
for (i = 0; i <= inputElements.length -1; i++)
{
if (isCheckBox(inputElements[i]))
{
if (inputElements[i].disabled == false)
{
checkboxesArray.push(inputElements[i]);
}
}
}
return checkboxesArray;
}
// checks if the elements is a checkbox or not
function isCheckBox(element)
{
return element.type == "checkbox";
}
I have a gridview control with a checkbox control in each row of data.
based on some database value some of the rows in the gridview have a Blue background color.
I need a button using javascript to TICK the checkbox in the all the rows where the background color of the row is BLUE.
is it possible to modify the following Javascript to do the required function on a button click.
// toggle state of the checkbox between selected and not selected!
function toggleCheckBoxes(gvId, isChecked)
{
var checkboxes = getCheckBoxesFrom(document.getElementById(gvId));
for (i = 0; i <= checkboxes.length - 1; i++)
{
checkboxes[i].checked = isChecked;
}
}
// get all the checkboxes from the container control
function getCheckBoxesFrom(gv)
{
var checkboxesArray = new Array();
var inputElements = gv.getElementsByTagName("input");
//var inputElements = gv.getElementsById("chkAll");
if (inputElements.length == 0) null;
for (i = 0; i <= inputElements.length -1; i++)
{
if (isCheckBox(inputElements[i]))
{
if (inputElements[i].disabled == false)
{
checkboxesArray.push(inputElements[i]);
}
}
}
return checkboxesArray;
}
// checks if the elements is a checkbox or not
function isCheckBox(element)
{
return element.type == "checkbox";
}