I have a checkbox in a GridDataControl column. How can I handle when the checkbox gets checked or not?
I found the GridDataControl.CurrentCellChanged event, but now how do I get the new value of the cell? It doesn't seem to make updates to the underlying model.
Hi Brent,
We have analyzed your Query.
You can achieve your requirement by using ControlValue.This ControlValue holds the Newly Updated Value.
You can refer the below Code Snippet to achieve your requirement.
Code snippet [C#]:
this.SyncGrid.CurrentCellChanged += new Syncfusion.Windows.ComponentModel. GridRoutedEventHandler(SyncGrid_CurrentCellChanged);
void SyncGrid_CurrentCellChanged(object sender, Syncfusion.Windows.ComponentModel. SyncfusionRoutedEventArgs args) { var currentcellmanager = this.SyncGrid.Model.CurrencyManager; if (currentcellmanager.CurrentCell.HasCurrentCell) { var currentcell = currentcellmanager.CurrentCell; if (currentcell.Renderer is GridCellCheckboxRenderer) { var value = currentcell.Renderer.ControlValue as bool?; if ((bool)value) { MessageBox.Show("CHECKED"); } else { MessageBox.Show("UNCHECKED"); }
}
}
|
We have prepared a sample based on this and you can find the sample under the following location:
Sample : checkboxevent.zip
Please let us know if this helps.
Thanks/Regards,
Kasthuriraja.G
<asp:UpdatePanel runat="server">
<ContentTemplate>
<script type="text/x-jsrender" id="columnTemplate">
<input type="checkbox" id="check{{:EmployeeID}}" onclick="myfunc(event)" name="CheckBoxColumn" />
</script>
<div>
<ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowPaging="True" IsResponsive="true" OnServerRecordClick="FlatGrid_ServerRecordClick">
<Columns>
<ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="75" />
<ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80" />
<ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Right" Width="75" Priority="4" />
<ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="75" Format="{0:C}" Priority="3" />
<ej:Column HeaderText="CheckBox" Template="#columnTemplate" TextAlign="Center" Width="110" />
</Columns>
<ClientSideEvents TemplateRefresh="templaterefresh" RecordClick="RecordClick" ActionComplete="complete" />
</ej:Grid>
</div>
<script type="text/javascript">
var id, state;
function myfunc(e) {
id = $(e.target).attr("id");
state = $(e.target).prop("checked");
triggerEvent(e);
}
function triggerEvent(e) {
var obj = $(".e-grid").data("ejGrid");
var args = { currentTarget: e.currentTarget.name, selectedRecord: obj.getSelectedRecords(), selectedIndex: obj.model.selectedRowIndex };
obj._trigger("recordClick", args);
}
function RecordClick(e) {
if (e.currentTarget != "CheckBoxColumn")
return false
else {
triggerEvent(e);
}
}
function complete(args) {
setTimeout(function () {
$("#" + id).prop("checked", state);
}, 500)
}
</script>
</ContentTemplate>
</asp:UpdatePanel> |