I am using a CheckboxList control, with one item labeled 'None'. For instance, 'Item 1', 'Item 2', 'Item 3', 'None'. I would like any other selected items to be deselected when the user clicks None.
I currently have a method called by the control's Change event, and can see if one of the items selected is 'None'. I now need to be able to deselect any of the other items.
public void OnChange(IEnumerable args)
{
if (args.ToList().Any(s => s == IdForNone) // If any of the selected items has an ID that matches the 'None' id
{
// How do I deselect the other items?
}
}
... @code{
RadzenCheckBoxList? itemTypeCheckboxList;
...
public void ValidateItems(IEnumerable args)
{
var itemList = args.ToList(); // I believe that at this point args is
// interchangable with Model.SelectedIds
var itemNoneId = itemTypeNone!.ItemTypeId.GetValueOrDefa
// If the last selected arg is for the 'None' treatment type
if (itemList.Last() == itemNoneId)
{
Model.SelectedIds = new int[] { itemNoneId };
itemList.RemoveAll(s => s != itemNoneId);
}
else
{
itemList.RemoveAll(s => s == itemNoneId);
Model.SelectedIds = itemList;
}
// If they select 'Other' show a textbox that they can fill in.
if (itemList.Any(s => s == itemTypeOther!.ItemTypeId))
{
showOtherItem = true;
}
else
{
showOtherItem= false;
}