简体   繁体   中英

Setting GridCheckBoxColumn in Telerik RadGrid from the client side

I have a GridCheckBoxColumn inside a Telerik RadGrid. I want to loop through all the rows on the client side and set the value of each checkbox. I can't figure out how to get the checkbox control. So far I have:

            var grid = $find("<%=RadGrid1.ClientID %>");
            var masterTableView = grid.get_masterTableView();
            if (masterTableView != null) {
                var gridItems = masterTableView.get_dataItems();
                var i;
                for (i = 0; i < gridItems.length; ++i) {
                    var gridItem = gridItems[i];
                    // How do I get the checkbox here? Note - since it's a CheckBox column, 
                    // I don't know the id of the checkbox.

                    // This doesn't work:
                    var control = gridItem.Controls[0];
                    control.checked = false;  
                }
            }

I figured it out. Here's how I did it:

 var grid = $find("<%=RadGrid1.ClientID %>");
 var masterTableView = grid.get_masterTableView();
 if (masterTableView != null) {
     var gridItems = masterTableView.get_dataItems();
     var i;
     for (i = 0; i < gridItems.length; ++i) {
         var gridItem = gridItems[i];
         var cell = gridItem.get_cell("chkSelect");
         var controlsArray = cell.getElementsByTagName('input');
         if (controlsArray.length > 0) {
             var rdo = controlsArray[0];
             rdo.checked = header_checkbox.checked;
         }
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM