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

[Solved] Grid and Templated Checkboxes

3 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 14 Aug 2009, 05:37 PM

Here is the delema.  I have 2 GridTemplateColumns.  Each Conatin a Checkbox.  this is also located in a DetailTable

 <telerik:GridTemplateColumn HeaderText="Suppress">  
                            <ItemTemplate>                                 
                                <asp:CheckBox ID="cbSuppress3" runat="server" /> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn HeaderText="Approve">  
                            <ItemTemplate>                                 
                                <asp:CheckBox ID="cbApprove3" runat="server" /> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 

I when one box is checked I need to make sure the other is not, if it is I need to uncheck it .  This will be true for each row.  I would like to do this on the client side to prevent a trip to the server.  Any Ideas?

Thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Aug 2009, 07:22 AM
Hi Randy,

Give a try with the following approach and see whether it meets your requirement.

ASPX:
 
 <telerik:GridTemplateColumn HeaderText="Suppress" UniqueName="Suppress" > 
                                <ItemTemplate> 
                                    <asp:CheckBox ID="cbSuppress3" runat="server"  Onclick="CheckChanged(this);" /> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Approve" UniqueName="Approve"   > 
                                <ItemTemplate> 
                                    <asp:CheckBox ID="cbApprove3" runat="server" Onclick="CheckChanged(this);" /> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
 
 

JS:
 
<script type="text/javascript" > 
 function CheckChanged(CheckBox) 
 { 
  
  var rowIndex=CheckBox.parentNode.parentNode.sectionRowIndex;  
  var childTable = $find("RadGrid1")._detailTables[0]; 
   
  var chkbx1=childTable.get_dataItems()[rowIndex].findElement("cbSuppress3");  
  var chkbx2=childTable.get_dataItems()[rowIndex].findElement("cbApprove3"); 
 
  if((CheckBox.checked)&&(CheckBox.id==chkbx1.id))  
  { 
     chkbx2.checked=false
   } 
  else if((CheckBox.checked)&&(CheckBox.id==chkbx2.id)) 
  { 
     chkbx1.checked=false
     
   } 
   
 } 
</script> 


Best Regards
Princy
0
Randy
Top achievements
Rank 1
answered on 17 Aug 2009, 11:33 AM
I am getting the following Javascript error _detailTables is null or not an object. Not sure if it matters, but in this case these check boxes are in the 2nd details table:  Master--> Detail--> Detail1

0
Princy
Top achievements
Rank 2
answered on 18 Aug 2009, 04:51 AM
Hi Randy,

I have modified the code since you mentioned in the above post that the GridTemplateColumns are placed in the 2nd level Detail table.

JS:
 
<script type="text/javascript"
 function CheckChanged(CheckBox) 
 { 
  
  var rowIndex=CheckBox.parentNode.parentNode.sectionRowIndex;  
  var childTable = $find("RadGrid1")._detailTables[1]; 
   
   
  var chkbx1=childTable.get_dataItems()[rowIndex].findElement("cbSuppress3");  
  var chkbx2=childTable.get_dataItems()[rowIndex].findElement("cbApprove3"); 
 
  if((CheckBox.checked)&&(CheckBox.id==chkbx1.id))  
  { 
     chkbx2.checked=false
   } 
  else if((CheckBox.checked)&&(CheckBox.id==chkbx2.id)) 
  { 
     chkbx1.checked=false
     
   } 
   
 } 
</script> 
 

If this does not help consider sending your entire aspx page.

Regards
Princy
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Randy
Top achievements
Rank 1
Share this question
or