Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
In a WebDataGrid with an UnboundCheckBoxField, how to hook a callback to the "checkbox clicked" event programmatically?
posted

I have a WebDataGrid to which I added an UnboundCheckBoxField.

Now I want to handle the "checkbox clicked" event on he client side. How to configure that programmatically?

I saw the example at "https://www.infragistics.com/help/aspnet/webdatagrid-handle-an-event-in-webdatagrid" but anyway I can't figure out how to do that for the "cell changed" event I need.

I guess I need to know what is the server-side handler I need to add, what is the behavior I need to add it to... But I can't find where is the documentation to all that.

Can anybody give me some guidance on that?

Parents
  • 1660
    Offline posted

    Hello Faustino,

    In order to handle the "checkbox clicked" event on the client side, for an UnboundCheckBoxField, you would need to handle the CellValueChanged event of the EditingCore behavior. It could be done with the following markup:

      <ig:EditingCore EnableInheritance="true" EditingClientEvents-CellValueChanged="CellValueChanged">
    
                            <Behaviors>
    
                                <ig:CellEditing>
    
                                </ig:CellEditing>
    
                            </Behaviors>
    
    </ig:EditingCore>
     

    The code for the event should be similar to the code below:

    function CellValueChanged(sender, e) {
    
                if (e.get_cell().get_column().get_key() === 'UnboundCheckBox') {
    
                    var row = e.get_cell().get_row();
    
                    var cellValue = e.get_cell().get_value();                               
    
                    // perform any operation you need
    
                }
    
            }

    Additionally, if you would like to handle the click event of the header checkbox, you can use the HeaderCheckBoxClicked event of the grid.

    Regarding server-side events, they are not bound to any behavior, unlike the client-side events, so handling the event could be done in the markup, inside the tag of the WebDataGrid or in code behind by assigning a handler for the event you are interested in.

    There is also no equivalent for the CellValueChanged event on the server, however the RowUpdating event could be used, which is raised once the user has finished editing of a certain row. There you could access the values of the bound and unbound fields in the event similar to how a value is accessed from a dictionary with key/value pairs, where the keys are the keys of the fields. The following properties of the event should be used e.Values[“key”] ir e.UnboundValues[“key”]. The following code could be used as a reference:

    protected void WebHierarchicalDataGrid1_RowUpdating(object sender, RowUpdatingEventArgs e)
    
            {
    
                bool? val = (bool)e.UnboundValues["UnboundCheckBox"];
    
                if (val != null) {
    
                    Debug.WriteLine("RowIndex: "+ e.Row.Index + "\nValue: " + val);               
    
                }
    
            }

    Please let me know if you need any further assistance.

    Regards,
    Ivan Kitanov

  • 30
    Verified Answer
    Offline posted in reply to Ivan Kitanov

    Ivan,

    Thank You for your quick response. 

    But, how can I do the markup part programmatically?

    Rewording the example at "">www.infragistics.com/.../webdatagrid-handle-an-event-in-webdatagrid" it should be something like:

    AddHandler Me.WebDataGrid1.Behaviors.EditingCore.EnableInheritance = True
    AddHandler Me.WebDataGrid1.Behaviors.EditingCore.EditingClientEvents.CellValueChanged, AddressOf EditingCore_CellValueChanged 
    ' Assign to the property the name of your client-side function
    Me.WebDataGrid1.Behaviors.EditingCore.EditingClientEvents.CellValueChanged = "CellValueChanged"

    but it doesn't work. It gives me two compiler errors:

    • 'CellValueChanged' is not an event of 'EditingClientEvents'.
    • 'EditingCore_CellValueChanged' is not declared. It may be inaccessible due to its protection level.

    (I can't use the markup in our task because we are using the WebDataGrid in a Web Forms custom control and the behaviors are aded programmatically. Even the EditingCore behavior is added only when the UnboundCheckboxField is requested to be shown)

Reply Children
No Data