This is a migrated thread and some comments may be shown as answers.

[Solved] Uncheck gridtemplatecolumn checkbox when row is deselected

2 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 15 May 2009, 04:53 PM
I have a grid that has clientside selecting enabled. I have a client select column and also a grid template column which has an item template of an asp checkbox. I want to wire the onrowdeselected client event so that when the row is deselected, the grid template column checkbox is also un selected. I need both checkboxes since they both mean different things. The clientselectcolumn indicated that this record is selected, and the template column is used as a flag to save in a certain way. If the record is not selected, the flag has no meaning since it won't be saved, so I want to uncheck it. How do I uncheck the asp checkbox on deselecting the row? Here is my code:

Here is my grid:
               <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"  AllowMultiRowSelection="True" 
                AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None" OnPreRender="packageGrid_PreRender" 
                 OnItemDataBound="packageGrid_ItemDataBound"
                <ClientSettings> 
                 <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> 
                 <ClientEvents OnRowDeselected="rowDeselected" /> 
                </ClientSettings> 
                <HeaderContextMenu EnableTheming="True" > 
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                </HeaderContextMenu> 
                <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px" /> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <telerik:GridClientSelectColumn UniqueName="rowSelectColumn" HeaderText="Selected"</telerik:GridClientSelectColumn> 
                        <telerik:GridBoundColumn DataField="package_id" Display="false"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="package_name" 
                            HeaderText="Package" SortExpression="package_name"  
                            UniqueName="package_name"
                        </telerik:GridBoundColumn> 
                    
                        <telerik:GridBoundColumn DataField="package_cd" HeaderText="Package code"  
                            SortExpression="package_cd" UniqueName="package_cd"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="descriptions" HeaderText="descriptions"  
                            SortExpression="descriptions" UniqueName="descriptions" Display="false"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="pkg_type" HeaderText="pkg_type"  
                            SortExpression="pkg_type" UniqueName="pkg_type" Display="false"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="active" HeaderText="Active"  
                            SortExpression="active" UniqueName="active"
                        </telerik:GridBoundColumn> 
                        <telerik:GridTemplateColumn DataField="OPENS_transform_flag" UniqueName="OPENS_transform_flag" HeaderText="Write to OPENS AS IS"
                         <ItemTemplate> 
                          <asp:CheckBox runat="server" ID="OPENS_transform_flag" /> 
                         </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridBoundColumn DataField="end_date" DataType="System.DateTime" Display="false"  
                            HeaderText="end_date" SortExpression="end_date" UniqueName="end_date"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                     
                </MasterTableView> 
                <FilterMenu EnableTheming="True"
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                </FilterMenu> 
            </telerik:RadGrid> 

And here is the javascript for the onrowdeselected event. I do not know what to put for the last line to uncheck the checkbox...

        function rowDeselected(sender, eventArgs) { 
 
            var dataItem = $get(eventArgs.get_id()); 
            var grid = sender; 
            var MasterTable = grid.get_masterTableView(); 
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
            var cell = MasterTable.getCellByColumnUniqueName(row, "OPENS_transform_flag"); 
 
            //  ??? What do I put here to uncheck this cell??? // 
 
        } 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 May 2009, 07:30 AM
Hello Laura,

You can access the checkbox in the template column in the row deselected client event and uncheck it as shown below:
js:
function rowDeselected(sender, eventArgs)  
      {           
            var dataItem = $get(eventArgs.get_id());  
            var grid = sender;  
            var MasterTable = grid.get_masterTableView();  
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];   
           
            var checkboxes = row._element.getElementsByTagName("INPUT"); 
            var index;                        
            for(index = 0; index < checkboxes.length; index++)   
             {                         
               if(checkboxes[index].id.indexOf("OPENS_transform_flag")!=-1)   
                   {                           
                       checkboxes[index].checked = false;        
                   }   
             }   
        }  

Thanks
Princy.
0
Laura
Top achievements
Rank 1
answered on 19 May 2009, 01:31 PM
Once again, thanks
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Laura
Top achievements
Rank 1
Share this question
or