<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kit Menke&#039;s Blog &#187; Event Handler</title>
	<atom:link href="http://kitmenke.com/blog/tag/event-handler/feed/" rel="self" type="application/rss+xml" />
	<link>http://kitmenke.com/blog</link>
	<description>Experiences with SharePoint, web development, and programming</description>
	<lastBuildDate>Fri, 20 Aug 2010 14:19:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Boolean values in an Event Handler</title>
		<link>http://kitmenke.com/blog/2009/07/13/boolean-values-in-an-event-handler/</link>
		<comments>http://kitmenke.com/blog/2009/07/13/boolean-values-in-an-event-handler/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 19:43:05 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Event Handler]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=99</guid>
		<description><![CDATA[While researching a bug with editing in datasheet view and a custom list event handler, I discovered strange behavior with boolean values. Any boolean value you get from the SPItemEventDataCollection depends on where the item was originally edited: either using the regular user interface (EditForm.aspx, NewForm.aspx) or using datasheet view. Here is the code to get a [...]]]></description>
			<content:encoded><![CDATA[<p>While researching a bug with editing in datasheet view and a custom list event handler, I discovered strange behavior with boolean values. Any boolean value you get from the SPItemEventDataCollection depends on where the item was originally edited: either using the regular user interface (EditForm.aspx, NewForm.aspx) or using datasheet view.</p>
<p><span id="more-99"></span></p>
<p>Here is the code to get a boolean item out of the list:</p>
<pre lang="csharp" escaped="true">private static bool GetItemColumnAsBoolean(SPItemEventDataCollection item, string columnName)
{
    bool value = false;

    if (null != item[columnName])
    {
        string booleanString = item[columnName].ToString();

        // values are different in datasheet view
        if (null != booleanString)
        {
            booleanString = booleanString.ToLower().Trim();
            switch (booleanString)
            {
                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;
            }
        }
    }

    return value;
}</pre>
<p>When an item was edited using the datasheet view you will be returned integer values:</p>
<ul>
<li>0 for False</li>
<li>-1 if the user clicks the checkbox in datasheet view and saves</li>
<li>1 if there was a boolean value anywhere in the item (and its value was already true)</li>
</ul>
<p>Normally, you are just returned &#8220;True&#8221; or &#8220;False&#8221;.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=99&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/07/13/boolean-values-in-an-event-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
