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://es.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?
Yes! I realized the code I was trying to reword from the example was for the server-side event. As you say, for the client-side events it is enough to assign the name of the function to the appropriate string property.
Hello Faustino,
The code for setting the client-side event should be the following:
Me.WebDataGrid1.Behaviors.EditingCore.EditingClientEvents.CellValueChanged = "CellValueChanged"
The string should be the name of the JavaScript function used as an event handler of the event inside the page of the user control.
Please let me know if you need any further assistance.
Regards, 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:
(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)
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); } }