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

Getting a client-side reference to edit controls in grid

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Amanda asked on 03 Jul 2008, 06:29 PM
I have a radgrid with a popup edit form, and I need to enable/disable a second checkbox based on whether the first checkbox is checked.  I'm doing a similar type of operation with a pair of RadComboBoxes, using the Telerik.Web.UI.RadComboBox.ComboBoxes[] array to find my controls' clientID's.  I tried probably three or four other approaches and never was succesful, but this works quite well.  Is there a similar array for all controls I could access?  Or do  you have a better suggestion for how to get the clientID of these checkboxes so I can turn them off and on?

Thanks -- Amanda

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 07 Jul 2008, 10:34 AM
Hi Amanda,

My suggestion is to set AutoPostBack = true for the first checkbox, intercept its OnCheckedChanged event and enable/disable the second checkbox based on the checked state of the first. Review the implementation presented in the following online resources for more details:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/gridreferencecontrolsinroweditform.html

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 2
answered on 07 Jul 2008, 11:28 AM
Hi Amanda,

You can try the following code snippet to achieve the desired scenario.

ASPX:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                         <EditItemTemplate> 
                             <asp:CheckBox ID="CheckBox1"  AutoPostBack="true" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" /> 
                         </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn UniqueName="TemplateColumn1">  
                         <EditItemTemplate> 
                             <asp:CheckBox ID="CheckBox2" Enabled="false" runat="server" /> 
                         </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 

CS:
 protected void CheckBox1_CheckedChanged(object sender, EventArgs e)  
    {  
        CheckBox chkbx1 = (CheckBox)sender;  
        GridEditableItem editeditem=(chkbx1).NamingContainer as GridEditableItem;  
        CheckBox chkbx2 = (CheckBox)editeditem.FindControl("CheckBox2");  
        if (chkbx1.Checked)  
        {  
            chkbx2.Enabled = true;  
        }  
        else  
            chkbx2.Enabled = false;  
     } 


Hope this helps..
Princy.
0
Amanda
Top achievements
Rank 1
answered on 23 Jul 2008, 05:40 PM
Well, I really didn't want to do a postback for something this simple, so what I ended up doing was passing in (this) to the client-side function, which gave me the client id of the clicked checkbox, then used a simple call to replace to get the name of the other checkbox.  Then it was trivial to set the required states.
Tags
Grid
Asked by
Amanda
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Princy
Top achievements
Rank 2
Amanda
Top achievements
Rank 1
Share this question
or