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

[Solved] Clientside Events and access to edit controls

2 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Wolfe
Top achievements
Rank 1
Steve Wolfe asked on 25 Jan 2010, 05:51 PM
I have a grid that has the following column definition:

            <telerik:GridCheckBoxColumn DataField="Dhcp" HeaderText="DHCP"></telerik:GridCheckBoxColumn> 
            <telerik:GridBoundColumn DataField="Address" HeaderText="Address"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Mask" HeaderText="Mask" ></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn  DataField="Gateway" HeaderText="Gateway" ></telerik:GridBoundColumn> 
 

I want to add a client side click handler to the DHCP CheckBox column.  Inside the handler I want to be able enable/disable all of the other GridBoundColumns based on whether or not the CheckBox is checked or not.

So a couple of questions:
  1. How do you add a client side event handler to the GridCheckBoxColumn
  2. How do you access the edit controls of the GridBoundColumns in that event handler.

Thanks,
Steve

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Jan 2010, 06:16 AM
Hello Steve,

Try out the following code to achieve the required:
c#:
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
       if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem editForm = (GridEditableItem)e.Item; 
            CheckBox chk = (CheckBox)(editForm["DHCPColumnUniqueName"].Controls[0]); 
              TextBox address = (TextBox)(editForm["AddressColumnUniqueName"].Controls[0]); 
              TextBox mask = (TextBox)(editForm["MaskColumnUniqueName"].Controls[0]); 
              TextBox gateway= (TextBox)(editForm["GatewayColumnUniqueName"].Controls[0]); 
              chk.Attributes.Add("onClick""CustomEventHandler(this,'" + address.ClientID + "','" + mask.ClientID + "','" + gateway.ClientID + "')");           
             
        }           
    } 

js:
function CustomEventHandler(checkbox,address,mask,gateway) 
    {    
         var address = document.getElementById(address); 
         var mask = document.getElementById(mask); 
         var gateway = document.getElementById(gateway); 
         if(checkbox.checked) 
         { 
            address.disabled = true
            mask.disabled = true
            gateway.disabled = true
         } 
         else         
         { 
            address.disabled = false
            mask.disabled = false
            gateway.disabled = false
         } 
    } 

Hope this helps..
Princy.
0
Steve Wolfe
Top achievements
Rank 1
answered on 27 Jan 2010, 07:18 AM
Princy,

Thanks! This is exactly what I was looking for.   Clicking the checkbox enables/disables on the controls client-side.  Now just to get the initial state set properly. I am guessing I need to do something similar, perhaps in DataBinding. 

Is there an event I could set to call that same method, to set the initial state client-side?


Thanks again!!
-Steve
Tags
Grid
Asked by
Steve Wolfe
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve Wolfe
Top achievements
Rank 1
Share this question
or