|
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...
|
|
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!
|
|
Rank: Member Groups: Member
Joined: 11/7/2013 Posts: 12
|
Wow. Thank you. So obvious I just didn't see it....
|
|
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"); } } }
|
|
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!
|
|
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!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Glad to hear that you got it working. And thanks for sharing!
|
|