Situation in a VS2010/SP2010 site:
List A with main items
List B with subitems, having a lookup column that points to List A ID
There are about 200 subitems for each item

The Page where users edit info regarding a main item (several fields) also allows users to change info regarding any of the 200 subitems (just a value), delete any of them or add new ones (there will be very few deletions or insertions).

When users click a button to save changes, main item is updated. At this moment each of the 200 subitems might also need updating.

So what's best approach?
- Delete the 200 old items by lookup id and re-insert the 200 new having the new values?

var query = from SPListItem item in listSubItems.Items
where (item["idLookup"].ToString() == id_Lookup)
    select item;
while (query.Count() > 0)

String[,] array_itemID_itemValue = ...;
for (int i = 0, i < 200, i++ )
    SPListItem item = listSubItems.AddItem();
    item["idLookup"] = id_Lookup;
    item["idSubItem"] = array_itemID_itemValue[i,0];
    item["valueColumn"] = array_itemID_itemValue[i,1];
  • Or else, instead of deleting and then re-inserting, do all the necessary updates inside of the while (query.Count() > 0) cycle, by searching the array_itemID_itemValue for each item on the subItems list, deleting those which are not in the array. Then add the new items from the array.
  • Or some other approach/way...

  • If 1st approach is best, is there no way to bulk delete?


You can consider the below link if you decided to use the bulk delete, well this can still be useful for bulk update


Not the answer you're looking for? Browse other questions tagged or ask your own question.