Hi,
Am using unboundcheckbox field in my webdatagrid. I need to disable the checkbox after 20 selections. How can i achieve it with using the row updating event.
Thanks,
vignesh
Hello Vignesh,
Thank you for posting in our forums!
If you are causing a postback each time a checkbox is selected, you could set a ColumnSetting so the column is set to ReadOnly. This forum thread shows a simple example
If you are not causing postbacks, you will need to handle this in javascript using the EditingCore's CellValueChanging event. In this event, you can create your logic to check if the user has made 20 selections and then call eventArgs.set_cancel(true) to prevent other checkboxes from being checked or unchecked. This forum thread provides an example of how you can handle the CellValueChanging event.
Please let me know if you need further assistance with this and I will be glad to help.
Here I have attached the javascript for getting the count of checkboxes I check. After 20 checkboxes I will display a confirm message box. If I try for “eventArgs.set_cancel(true);” am not able to get it. As it does not accept the “.set_cancel”. Please help me to disable after 20 records selection. Thanks in advance.
function webdatagrid1_Editing_CellValueChanged(sender, eventArgs)
{
var grid = $find("wdgMasterProject");
var columnKey = eventArgs.get_cell().get_column().get_key();
if (columnKey == "chkSelect") {
var rowsCount = grid.get_rows().get_length();
var number = document.getElementById("txtHidden").value;
for (var i = 0; i < rowsCount; i++) {
if (grid.get_rows().get_row(i).get_cellByColumnKey("chkSelect").get_value()) {
number = document.getElementById("txtHidden").value;
number++;
//alert(selRowsCount);
}
document.getElementById("txtHidden").value = number;
if (number > 20)
confirm("Please select only 20 values");
set_cancel is not available in the CellValueChanged event. You should use the CellValueChanging event in order to cancel and prevent the user from selecting further checkboxes.
Typically, our event naming follows the pattern that events ending in "ing" can be cancelled before an event ending in "ed" will fire. You can find additional information on this in our documentation here and here.
If you need further assistance with this, please let me know. Additionally, I would like to let you know that I will be out of the office on Monday May, 30th I will review any updates on Tuesday May 31st and respond to you then.
Hi Micheal ,
Thank You, it is working now. But I have a problem like if I select a checkbox and deselect it is again remains the same as selected, means if I select first 15 values and deselect 2 of then and in pagination of another page if I select some 7 values it is not accepting. It again disables the selection at my fifth selection in the other page as well. Please help me how to fix that.
And also could you tell me how to continue the pagination values in the webdatagrid, Like I have limited the paging size to 15 values. in the checkbox if I go to the second page and started checking, it again takes the values as starting from 1. Please tell me how to continue the numbering with the checkboxes selection from page to page.
Thanks in advance.!
I am glad the CellValueChanging event is working for your needs.
As for the two issues you are asking about, the way you describe them sounds like they conflict with each other. In the first question, changing pages stores a number of checkboxes selected. But, in the second question you say that changing pages does not store any number of checkboxes. Are there any other differences between these two scenarios that could explain their behaviors?
I would recommend checking your code's logic in the CellValueChanging event. I noticed in your previous post that you are only storing and incrementing the number variable, which may be part of the issue.