Welcome Guest Search | Active Topics | Sign In | Register

Check All in checkbox column Options
Mike
Posted: Thursday, January 30, 2014 3:19:11 PM
Rank: Member
Groups: Member

Joined: 11/7/2013
Posts: 12
I've been struggling with this code all day. Seems to fire ok, but the gridCell.setValue("1") comes back with an 'SCRIPT5009: 'gridcell' is undefined.'

function check_all() {
//Get the grid object. This code assumes the Grid's ClientID is
//"Grid1", you will need to change this the real ClientID of your
//Grid
//alert("your here");
var grid = eo_GetObject("ctl00_ContentPlaceHolder1_RecipientList");

//Loop through all grid items
for (var i = 0; i < grid.getItemCount(); i++) {
//Get the grid item
var gridItem = grid.getItem(i);

//Get the grid cell
var gridCell = gridItem.getCell(0);

//Check/uncheck the cell. Use "1" to check the cell,
//use "0" to uncheck
gridcell.setValue("1");
}
}

I'm out of answers here - any help is appreciated...
eo_support
Posted: Thursday, January 30, 2014 3:26:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Your code looks perfectly fine. The only thing we can spot is when you declare gridCell, you have "gridCell", but when you use it, you use "gridcell". Note the case difference for the letter "c".

Thanks!
Mike
Posted: Thursday, January 30, 2014 3:28:58 PM
Rank: Member
Groups: Member

Joined: 11/7/2013
Posts: 12
Wow. Thank you. So obvious I just didn't see it....
Mike
Posted: Friday, January 31, 2014 2:09:38 PM
Rank: Member
Groups: Member

Joined: 11/7/2013
Posts: 12
I modified the code slightly so that I can clear all and select all. It works fine 1 time. After that the checkbox value always returns a "0". Am I approaching this correctly?

function check_all() {
//Get the grid object. This code assumes the Grid's ClientID is
//"Grid1", you will need to change this the real ClientID of your
//Grid
//alert("your here");
var grid = eo_GetObject("ctl00_ContentPlaceHolder1_RecipientList");

//Loop through all grid items
for (var i = 0; i < grid.getItemCount(); i++) {
//Get the grid item
var gridItem = grid.getItem(i);

//Get the grid cell
var gridCell = gridItem.getCell(0);

//Check/uncheck the cell. Use "1" to check the cell,
//use "0" to uncheck
if (gridCell.getValue("1"))
{
gridCell.setValue("0");
}
else
{
gridCell.setValue("1");
}
}
}
eo_support
Posted: Friday, January 31, 2014 4:56:42 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

I think you should use

Code: JavaScript
if (gridCell.getValue() == "1")


instead of:

Code: JavaScript
if (gridCell.getValue("1"))


Thanks!
Mike
Posted: Friday, February 7, 2014 7:50:52 AM
Rank: Member
Groups: Member

Joined: 11/7/2013
Posts: 12
Thanks for all the input... I ended up putting a checkbox in the column header text. Then I access that value in the javascript to populate the grid rows.

<eo:CheckBoxColumn Width="50" HeaderText='<div><input id="chkAll" type="checkbox" onclick="check_all();" /></div>' AllowResize="false" Name="ckBox">
<CheckBoxStyle CssText="" />
</eo:CheckBoxColumn>


<script type="text/javascript">
function check_all() {
var grid = eo_GetObject("ctl00_ContentPlaceHolder1_RecipientList");
var chkBox = document.getElementById("chkAll");

//Loop through all grid items
for (var i = 0; i < grid.getItemCount(); i++) {
//Get the grid item
var gridItem = grid.getItem(i);

//Get the grid cell
var gridCell = gridItem.getCell(0);

//Check/uncheck the cell. Use "1" to check the cell,
//use "0" to uncheck
if (chkBox.checked)
{
gridCell.setValue("1");
}
else
{
gridCell.setValue("0");
}
}
}
</script>

Works great!
eo_support
Posted: Friday, February 7, 2014 9:14:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Glad to hear that you got it working. And thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.