Friday, December 12, 2014

SharePoint Event Handlers and Checkbox Values

Found a new 'gotcha!' today.

 I have an event handler on a list. When an item changes, we update a database.

If the item has a checkbox value(we have a few), and the item is edited through the normal EditForm.aspx page, the code is presented with a True/False value for that checkbox item. No problem, works great, our Convert.ToBoolean(value) works fine.

 If the item is updated using the data sheet view, which, users tend to like on lists of 1000+ items, the code is presented with a 0/1/-1 value for the checkbox field! The Convert.ToBoolean(value) fails. causing an exception.


 Kit Menke's blog confirmed i'm not crazy: http://kitmenke.com/blog/2009/07/13/boolean-values-in-an-event-handler/

 So, to steal his explanation:
 case "-1": // user changed a boolean field to true in datasheet
 case "1": // field was already true in the item after a datasheet edit
 case "true": // normal edit (not using datasheet)
      value = true;
      break;