If the system is already on a working server and is working stably, please ignore my answer. If it is still in the planning / design / programming stage, I think that probably a small change in the database will make everything a lot easier.
Table SelectedItems RecordID CheckBoxID IsSelected 1 1 true 1 2 true 1 3 false 1 4 true
That is, for a specific RecordID and CheckBoxID, you do not need to query the table to find if there is a corresponding record (which means that it is selected). There is always such an entry with IsSelected status in the new design.
Meanwhile, this design is also very convenient for serving on your web pages. What you are changing is just the IsSelected value for a specific row, you do not need to worry about "Oh, do I need to delete one row or add it?" βIs the data in this row dirty or not?β ... things get simpler.
source share