<?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; Example</title>
	<atom:link href="http://kitmenke.com/blog/tag/example/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>Using undefined in JavaScript</title>
		<link>http://kitmenke.com/blog/2010/08/10/using-undefined-in-javascript/</link>
		<comments>http://kitmenke.com/blog/2010/08/10/using-undefined-in-javascript/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 17:37:52 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=269</guid>
		<description><![CDATA[Working with JavaScript can definitely be painful, but I always love stumbling across interesting and strange features of the language. I just found wtfjs.com which led me to these two answers on stackoverflow. The first answer made me realize that undefined is not a keyword in JavaScript; it actually is a type that also happens [...]]]></description>
			<content:encoded><![CDATA[<p>Working with JavaScript can definitely be painful, but I always love stumbling across interesting and strange features of the language. I just found <a href="http://wtfjs.com/">wtfjs.com</a> which led me to these <a href="http://stackoverflow.com/questions/1995113/strangest-language-feature/2008728#2008728">two</a> <a href="http://stackoverflow.com/questions/1995113/strangest-language-feature/2010740#2010740">answers</a> on stackoverflow.</p>
<p><span id="more-269"></span></p>
<p><a href="http://stackoverflow.com/questions/1995113/strangest-language-feature/2008728#2008728">The first answer</a> made me realize that <code class="codecolorer text default"><span class="text">undefined</span></code> is not a keyword in JavaScript; it actually is a <strong>type</strong> that also happens to have a global variable with the same name. This means that you can change the value of <code class="codecolorer text default"><span class="text">undefined</span></code> (the global variable) to be something else.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #000066; font-weight: bold;">typeof</span> undefined <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><br />
<span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> undefined <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><br />
<span style="color: #CC0000;">42</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #000066; font-weight: bold;">typeof</span> undefined <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><br />
<span style="color: #003366; font-weight: bold;">false</span></div></div>
<p>And, like shown above, the correct way to check if a variable is <code class="codecolorer text default"><span class="text">undefined</span></code> is by using <code class="codecolorer text default"><span class="text">typeof</span></code>.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #003366; font-weight: bold;">var</span> myVariable<span style="color: #339933;">;</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #000066; font-weight: bold;">typeof</span> myVariable<br />
<span style="color: #3366CC;">&quot;undefined&quot;</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> myVariable <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #CC0000;">1</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #000066; font-weight: bold;">typeof</span> myVariable<br />
<span style="color: #3366CC;">&quot;number&quot;</span></div></div>
<p><a href="http://stackoverflow.com/questions/1995113/strangest-language-feature/2010740#2010740">The second feature</a>, is something that I often used but had no idea why it actually worked: <code class="codecolorer text default"><span class="text">void(0)</span></code>.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:void(0)&quot;</span>&gt;</span>do nothing<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span></div></div>
<p>According to Breton&#8217;s excellent explanation, <code class="codecolorer text default"><span class="text">void</span></code> is actually a prefix operator. When you prefix any expression with <code class="codecolorer text default"><span class="text">void</span></code>, the result evaluates to <code class="codecolorer text default"><span class="text">undefined</span></code>. So, using our <em>correct</em> method for checking <code class="codecolorer text default"><span class="text">undefined</span></code> above you get this in the console:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><br />
<span style="color: #003366; font-weight: bold;">true</span></div></div>
<p>Awesome!</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=269&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/08/10/using-undefined-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrap ListViewWebPart Column Headers</title>
		<link>http://kitmenke.com/blog/2010/07/08/wrap-listviewwebpart-colum-headers/</link>
		<comments>http://kitmenke.com/blog/2010/07/08/wrap-listviewwebpart-colum-headers/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 18:55:58 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[MOSS2007]]></category>
		<category><![CDATA[WSS]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=258</guid>
		<description><![CDATA[I recently got asked if it was possible wrap the column headers in a list view web part. The user had a WebPart with quite a few columns with long names and was trying to prevent the page from scrolling left to right. What we needed to do was wrap the column header so that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got asked if it was possible wrap the column headers in a list view web part. The user had a WebPart with quite a few columns with long names and was trying to prevent the page from scrolling left to right.<br />
<span id="more-258"></span></p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/07/2010-07-08-13-48-02.png"><img class="alignnone size-full wp-image-259" title="Column Header (nowrap)" src="http://kitmenke.com/blog/wp-content/uploads/2010/07/2010-07-08-13-48-02.png" alt="Column Header (nowrap)" width="600" height="165" /></a></p>
<p>What we needed to do was wrap the column header so that it fit more to the data in the grid.</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/07/2010-07-08-13-47-27.png"><img class="alignnone size-full wp-image-260" title="Column Header (wrapped)" src="http://kitmenke.com/blog/wp-content/uploads/2010/07/2010-07-08-13-47-27.png" alt="Column Header (wrapped)" width="600" height="165" /></a></p>
<p>The solution is relatively simple to implement; all you need is a Content Editor Webpart at the bottom of the page somewhere with the following JavaScript in it:</p>
<pre lang="javascript" escaped="true">&lt;script type=&quot;text/javascript&quot;&gt;
function WrapColumnHeaderText(columnName) {
    try {
        var tables = document.getElementsByTagName(&quot;table&quot;);
        for (i = 0; i &lt; tables.length; i++) {
            // find the table that is for the column we're looking for
            var attrItem = tables[i].attributes.getNamedItem(&quot;displayname&quot;)
            if (null != attrItem &amp;&amp; attrItem.nodeValue === columnName) {
                var cells = tables[i].getElementsByTagName(&quot;td&quot;);
                for (c = 0; c &lt; cells.length; c++) {
                    if (null != cells[c].attributes.getNamedItem(&quot;nowrap&quot;)) {
                        cells[c].attributes.removeNamedItem(&quot;nowrap&quot;);
                        // after removing nowrap, IE won't actually wrap the content
                        // until it &quot;changes&quot;.. so we touch it to force it to wrap
                        cells[c].innerHTML = cells[c].innerHTML;
                        break;
                    }
                }
            }
        }
    } catch (ex) {
        alert(ex.toString());
    }
}

function WrapColumnHeaders() {
    // TODO: repeat the line below to wrap more columns
    WrapColumnHeaderText(&quot;Company Product Code&quot;);
}

_spBodyOnLoadFunctionNames.push(&quot;WrapColumnHeaders&quot;);
&lt;/script&gt;
</pre>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=258&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/07/08/wrap-listviewwebpart-colum-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple AJAX App using SharePoint Web Services</title>
		<link>http://kitmenke.com/blog/2010/03/14/a-simple-ajax-app-using-sharepoint-web-services/</link>
		<comments>http://kitmenke.com/blog/2010/03/14/a-simple-ajax-app-using-sharepoint-web-services/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 00:08:18 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=224</guid>
		<description><![CDATA[In this era of Web 2.0 web applications, I think it was only a matter of time before I needed to investigate how I could apply AJAX to SharePoint. With a little JavaScript and SharePoint&#8217;s web services, you can build fancy apps that can easily be dropped into a document library. And after reading Glen [...]]]></description>
			<content:encoded><![CDATA[<p>In this era of Web 2.0 web applications, I think it was only a matter of time before I needed to investigate how I could apply AJAX to SharePoint. With a little JavaScript and SharePoint&#8217;s web services, you can build fancy apps that can easily be dropped into a document library. And after reading <a href="http://blog.glenc.net/2007/04/20/calling-sharepoint-web-services-from-javascript/">Glen Cooper&#8217;s blog post</a> on the subject, I figured it was something definitely worth investigating.</p>
<p>I also took this opportunity to improve a process I have to do all the time: what are the internal column names in a list? To get the list information, I built a simple AJAX app that consumes the Lists.asmx web service. Please keep in mind that this code will have be uploaded into  SharePoint in order to work (a document library will work) and will not run from your desktop.</p>
<p><span id="more-224"></span></p>
<h2>Step 0: HTML for user input and displaying results</h2>
<p>Since I will be calling the GetList method on Lists.asmx, I will need two parameters from the user: Site URL and List Name. Site URL gives the web service context to a particular web and List Name should be a list within that web. I also specify a DIV which is where I will display the list&#8217;s information.</p>
<pre lang="html4strict" escaped="true">&lt;div id="controls"&gt;
   &lt;fieldset&gt;
      &lt;legend&gt;List Information&lt;/legend&gt;
      &lt;label for="txtSiteURL"&gt;Site URL:&lt;/label&gt;&lt;input id="txtSiteURL" type="text" style="width:400px" value="http://server/sites/SiteCollection/SubSite" /&gt;&lt;br/&gt;
      &lt;div&gt;Example: http://server/sites/SiteCollection/SubSite&lt;/div&gt;
      &lt;label for="txtListName"&gt;List Name:&lt;/label&gt;&lt;input id="txtListName" type="text" value="Images" /&gt;&lt;br/&gt;
      &lt;div&gt;Example: Images&lt;/div&gt;
      &lt;input id="btnExecute" type="button" value="Get Columns" /&gt;
   &lt;/fieldset&gt;
&lt;/div&gt;

&lt;div id="result"&gt;
   (results)
&lt;/div&gt;</pre>
<p>Now that we have our HTML form, we can work on the JavaScript code.</p>
<h2>Step 1: Building a SOAP Message</h2>
<p>To communicate with the web service, we need to use SOAP. Luckily, Glen has already created a very handy class for taking care of these operations. It is also reusable so it will come in handy for other web service calls. I tweaked his code a little bit and then put it into SoapUtils.js (also, please note this code depends on <a href="http://www.prototypejs.org/">Prototype.JS</a>):</p>
<pre lang="javascript" escaped="true">/*
SoapUtils.js
Author: Glen Cooper

http://blog.glenc.net/2007/04/20/calling-sharepoint-web-services-from-javascript/

*/
var Soap = {
   createEnvelope: function(action, ns, parameters) {
      var soap = '&lt;?xml version="1.0" encoding="utf-8"?&gt;';
      soap += '&lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;';
      soap += '  &lt;soap:Body&gt;';
      soap += '    &lt;' + action + ' xmlns="' + ns + '"&gt;';
      soap += Soap.__parseParameters(parameters);
      soap += '    &lt;/' + action + '&gt;';
      soap += '  &lt;/soap:Body&gt;';
      soap += '&lt;/soap:Envelope&gt;';
      return soap;
   },

   __parseParameters: function(parameters) {
      var params = "";
      if (typeof parameters == 'object') {
         // check if we were provided an array or an object
         if (typeof parameters.push == 'function') {
            for (var i = 0, length = parameters.length; i &lt; length; i += 2) {
               params += "&lt;" + parameters[i] + "&gt;" + parameters[i+1] + "&lt;/" + parameters[i] + "&gt;";
            }
         }
         else {
            $H(parameters).each(function(pair) {
               params += "&lt;" + pair.key + "&gt;" + pair.value + "&lt;/" + pair.key + "&gt;";
            });
         }
      }
      return params;
   }
}</pre>
<p>This utility class handles a lot of the grunt work for creating the SOAP message. It makes it pretty easy to grab the input, build the message, and then send it to the server. Next, I need to give it the specifics it needs to build the actual message. This is all contained inside my Execute function:</p>
<pre lang="javascript" escaped="true">function Execute() {
   $('result').innerHTML = "Executing..."

   var txtSiteUrl = $('txtSiteURL').getValue();
   var txtListName = $('txtListName').getValue();

   // build parameter object
   var parameters =
   {
      listName: txtListName
   }

   // create soap envelope
   // can find the action and namespace from the WSDL page
   // ex: http://servername/_vti_bin/Lists.asmx?op=GetList
   var soap = Soap.createEnvelope(
     "GetList", // action
     "http://schemas.microsoft.com/sharepoint/soap/", // namespace
     parameters);

   if (!txtSiteUrl.endsWith('/')) {
      txtSiteUrl += '/';
   }
   txtSiteUrl += '_vti_bin/Lists.asmx';

   // call web service
   new Ajax.Request(
     txtSiteUrl,
     {
       method: "post",
       contentType: "text/xml",
       postBody: soap,
       onSuccess: ajaxSuccess,
       onFailure: ajaxError
     });
}</pre>
<p>The Execute method is then bound to the &#8220;Get Columns&#8221; button on page load:</p>
<pre lang="javascript" escaped="true">Event.observe(window,'load',function(){
   Event.observe('btnExecute','click',Execute);
});</pre>
<h2>Step 2: Parsing the Web Service&#8217;s XML response</h2>
<p>At this point, we are ready to handle the response from the web service. Unfortunately, parsing XML using JavaScript was not exactly the easiest experience. I haven&#8217;t found an easy way to do it, so if you have any ideas, please let me know in the comments.</p>
<p>In any case, if an error occurs, I simply want to print the error message:</p>
<pre lang="javascript" escaped="true">function ajaxError(result) {
   Element.insert($('result'), {bottom:'&lt;span style="color:red"&gt;' + result.responseText + '&lt;/span&gt;'});
}</pre>
<p>A success message is a lot more complicated since we want to extract information out of the returned XML. In fact, if you look at the entire response from the webservice after calling GetList, the returned result for a simple Images library is something like 1100 lines of XML. The majority of this is taken up by the full description of each column in the list. There is a LOT of junk that we are simply going to be skipping over. For sanity sake, I&#8217;m not going to post the entire response, but useful snippets of interest.</p>
<p>Overall, the response will look something like:</p>
<pre lang="xml" escaped="true">&lt;GetListResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;
  &lt;GetListResult&gt;
    &lt;List RequireCheckout="False" EnableMinorVersion="False" ShowUser="True" Ordered="False" MultipleDataList="False" Hidden="False" EnableVersioning="True" EnableModeration="False" EnableAttachments="False" AllowMultiResponses="False" AllowDeletion="True" HasUniqueScopes="False" WorkFlowId="" MajorWithMinorVersionsLimit="0" MajorVersionLimit="0" ScopeId="317f19e2-4ba8-4ecc-82f3-9d846a270840" SendToLocation="" WebId="0bb1435c-d56a-4f6a-93a7-77ad6990a48c" WebFullUrl="/sites/SiteCollection/SubSite1/SubSite2" EmailAlias="" EmailInsertsFolder="" EventSinkData="" EventSinkClass="" EventSinkAssembly="" Author="630" WriteSecurity="1" ReadSecurity="1" RootFolder="/sites/SiteCollection/SubSite1/SubSite2/Images1" AnonymousPermMask="0" ItemCount="6" Flags="4232" WebImageHeight="480" WebImageWidth="640" ThumbnailSize="160" Direction="none" Version="0" LastDeleted="20081001 01:58:47" Modified="20100205 08:40:53" Created="20081001 01:58:47" ServerTemplate="109" FeatureId="00bfea71-52d4-45b3-b544-b1c71b620109" BaseType="1" Name="{2CDA4792-6D4E-4D9F-BC5B-F862D5235061}" ImageUrl="/_layouts/images/itil.gif" Description="" Title="Images" ID="{2CDA4792-6D4E-4D9F-BC5B-F862D5235061}" MobileDefaultViewUrl="" DefaultViewUrl="/sites/SiteCollection/SubSite1/SubSite2/Images1/Forms/AllItems.aspx" DocTemplateUrl=""&gt;
      &lt;Fields&gt;
        ... all fields are listed here in &lt;Field&gt; nodes
      &lt;/Fields&gt;
      &lt;RegionalSettings&gt;
         ...
      &lt;/RegionalSettings&gt;
      &lt;ServerSettings&gt;
         ...
      &lt;/ServerSettings&gt;
    &lt;/List&gt;
  &lt;/GetListResult&gt;
&lt;/GetListResponse&gt;</pre>
<p>Notice, the List node contains a LOT of useful information. Once we have that node, we can display a lot of it using this function:</p>
<pre lang="javascript" escaped="true">function addListInformation(nodeList) {
   var listTitle = nodeList.attributes.getNamedItem('Title').value;
   var listImg = nodeList.attributes.getNamedItem('ImageUrl').value;
   var listDesc = nodeList.attributes.getNamedItem('Description').value;
   var listCount = nodeList.attributes.getNamedItem('ItemCount').value;
   var listViewURL = nodeList.attributes.getNamedItem('DefaultViewUrl').value;

   var output = '&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;a href="' + listViewURL + '"&gt;&lt;img src="' + listImg + '" alt="' + listTitle + '" /&gt;&lt;/a&gt;&lt;/td&gt;'
   output += '&lt;td&gt;&lt;a href="' + listViewURL + '"&gt;' + listTitle + '&lt;/a&gt;&lt;/td&gt;';
   output += '&lt;td&gt;# of items = ' + listCount + '&lt;/td&gt;';
   output += '&lt;td&gt;' + listDesc + '&lt;/td&gt;&lt;/div&gt;&lt;/tr&gt;&lt;/table&gt;';
   Element.insert('result', {bottom:output});
}</pre>
<p>Also, since we are interested in the internal column names, we want information about each of the fields. All of the columns are listed inside the Fields node (see above). A lot of them have attributes similar to below:</p>
<pre lang="xml" escaped="true">&lt;Field FromBaseType="TRUE" StaticName="Created" SourceID="http://schemas.microsoft.com/sharepoint/v3" StorageTZ="TRUE" DisplayName="Created" Name="Created" Type="DateTime" ReadOnly="TRUE" RowOrdinal="0" ColName="tp_Created" ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}"&gt;&lt;/Field&gt;
&lt;Field FromBaseType="TRUE" StaticName="Author" SourceID="http://schemas.microsoft.com/sharepoint/v3" DisplayName="Created By" Name="Author" List="UserInfo" Type="User" ReadOnly="TRUE" RowOrdinal="0" ColName="tp_Author" ID="{1df5e554-ec7e-46a6-901d-d85a3881cb18}"&gt;&lt;/Field&gt;</pre>
<p>So, for each of the Field nodes, we are interested in the StaticName and DisplayName attributes:</p>
<pre lang="javascript" escaped="true">function addFieldInformation(nodes) {
   if (nodes.length &lt;= 0) {
      Element.insert(container, {bottom:"No results to display."});
      return;
   }

   var output = '&lt;table cellpadding="0" cellspacing="0" border="1"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Display Name&lt;/th&gt;&lt;th&gt;Internal Name&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
   for (i = 0; i &lt; nodes.length; i++) {
      var attr = nodes[i].attributes;
      // there are a lot more attributes, but right now only care about the Display Name
      // and the internal name
      var displayName = attr.getNamedItem('DisplayName').value;
      var internalName = attr.getNamedItem('StaticName').value;
      output += '&lt;tr&gt;&lt;td&gt;' + displayName + '&lt;/td&gt;&lt;td&gt;' + internalName + '&lt;/td&gt;&lt;/tr&gt;';
   }
   output += '&lt;/tbody&gt;&lt;/table&gt;';

   Element.insert('result', {bottom:output});
}</pre>
<p>And finally, to bring it all together, we are calling these functions inside our success function:</p>
<pre lang="javascript" escaped="true">function ajaxSuccess(result) {
   // we're going to be adding HTML so reset this to be empty
   $('result').innerHTML = "";

   // put it in xmlDoc to make it shorter
   var xmlDoc = result.responseXML;

   // get the List node and show some of the attributes that are interesting
   addListInformation(xmlDoc.getElementsByTagName("List")[0]);
   // then select the Fields node and get all of its children (Field nodes)
   addFieldInformation(xmlDoc.getElementsByTagName("Fields")[0].childNodes);
}</pre>
<p>All together now:</p>
<pre lang="html4strict" escaped="true">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"&gt;

&lt;html&gt;

&lt;head&gt;

&lt;title&gt;List Information - Kit's Utilities&lt;/title&gt;

&lt;!-- Include our style reset (for fun!) and our new stylesheet --&gt;
&lt;link href="css/reset.css" rel="stylesheet" type="text/css" /&gt;
&lt;link href="css/utilities.css" rel="stylesheet" type="text/css" /&gt;

&lt;!-- Include files used for ajax, etc --&gt;
&lt;script type="text/javascript" src="scriptaculous/prototype.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="ajax/SoapUtils.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="ajax/SearchWSUtils.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
Event.observe(window,'load',function(){
   Event.observe('btnExecute','click',Execute);
});

function Execute() {
   $('result').innerHTML = "Executing..."

   var txtSiteUrl = $('txtSiteURL').getValue();
   var txtListName = $('txtListName').getValue();

   // build parameter object
   var parameters =
   {
      listName: txtListName
   }

   // create soap envelope
   // can find the action and namespace from the WSDL page
   // ex: http://servername/_vti_bin/Lists.asmx?op=GetList
   var soap = Soap.createEnvelope(
     "GetList", // action
     "http://schemas.microsoft.com/sharepoint/soap/", // namespace
     parameters);

   if (!txtSiteUrl.endsWith('/')) {
      txtSiteUrl += '/';
   }
   txtSiteUrl += '_vti_bin/Lists.asmx';

   // call web service
   new Ajax.Request(
     txtSiteUrl,
     {
       method: "post",
       contentType: "text/xml",
       postBody: soap,
       onSuccess: ajaxSuccess,
       onFailure: ajaxError
     });
}

function ajaxSuccess(result) {
   // we're going to be adding HTML so reset this to be empty
   $('result').innerHTML = "";

   // put it in xmlDoc to make it shorter
   var xmlDoc = result.responseXML;

   // get the List node and show some of the attributes that are interesting
   addListInformation(xmlDoc.getElementsByTagName("List")[0]);
   // then select the Fields node and get all of its children (Field nodes)
   addFieldInformation(xmlDoc.getElementsByTagName("Fields")[0].childNodes);
}

function addListInformation(nodeList) {
   var listTitle = nodeList.attributes.getNamedItem('Title').value;
   var listImg = nodeList.attributes.getNamedItem('ImageUrl').value;
   var listDesc = nodeList.attributes.getNamedItem('Description').value;
   var listCount = nodeList.attributes.getNamedItem('ItemCount').value;
   var listViewURL = nodeList.attributes.getNamedItem('DefaultViewUrl').value;

   var output = '&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;a href="' + listViewURL + '"&gt;&lt;img src="' + listImg + '" alt="' + listTitle + '" /&gt;&lt;/a&gt;&lt;/td&gt;'
   output += '&lt;td&gt;&lt;a href="' + listViewURL + '"&gt;' + listTitle + '&lt;/a&gt;&lt;/td&gt;';
   output += '&lt;td&gt;# of items = ' + listCount + '&lt;/td&gt;';
   output += '&lt;td&gt;' + listDesc + '&lt;/td&gt;&lt;/div&gt;&lt;/tr&gt;&lt;/table&gt;';
   Element.insert('result', {bottom:output});
}

function addFieldInformation(nodes) {
   if (nodes.length &lt;= 0) {
      Element.insert(container, {bottom:"No results to display."});
      return;
   }

   var output = '&lt;table cellpadding="0" cellspacing="0" border="1"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Display Name&lt;/th&gt;&lt;th&gt;Internal Name&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
   for (i = 0; i &lt; nodes.length; i++) {
      var attr = nodes[i].attributes;
      // there are a lot more attributes, but right now only care about the Display Name
      // and the internal name
      var displayName = attr.getNamedItem('DisplayName').value;
      var internalName = attr.getNamedItem('StaticName').value;
      output += '&lt;tr&gt;&lt;td&gt;' + displayName + '&lt;/td&gt;&lt;td&gt;' + internalName + '&lt;/td&gt;&lt;/tr&gt;';
   }
   output += '&lt;/tbody&gt;&lt;/table&gt;';

   Element.insert('result', {bottom:output});
}

function ajaxError(result) {
   Element.insert($('result'), {bottom:'&lt;span style="color:red"&gt;' + result.responseText + '&lt;/span&gt;'});
}

&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;div id="container"&gt;
   &lt;div id="controls"&gt;
      &lt;fieldset&gt;
         &lt;legend&gt;List Information&lt;/legend&gt;
         &lt;label for="txtSiteURL"&gt;Site URL:&lt;/label&gt;&lt;input id="txtSiteURL" type="text" style="width:400px" value="http://server/sites/SiteCollection/SubSite" /&gt;&lt;br/&gt;
         &lt;div&gt;Example: http://server/sites/SiteCollection/SubSite&lt;/div&gt;
         &lt;label for="txtListName"&gt;List Name:&lt;/label&gt;&lt;input id="txtListName" type="text" value="Images" /&gt;&lt;br/&gt;
         &lt;div&gt;Example: Images&lt;/div&gt;
         &lt;input id="btnExecute" type="button" value="Get Columns" /&gt;
      &lt;/fieldset&gt;
   &lt;/div&gt;

   &lt;div id="result"&gt;
      (results)
   &lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=224&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/03/14/a-simple-ajax-app-using-sharepoint-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autopopulate a SharePoint Form from URL</title>
		<link>http://kitmenke.com/blog/2010/03/11/autopopulate-a-sharepoint-form-from-url/</link>
		<comments>http://kitmenke.com/blog/2010/03/11/autopopulate-a-sharepoint-form-from-url/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 17:28:02 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=237</guid>
		<description><![CDATA[August 20, 2010 Update: The code below has moved to be part of a bigger library&#8230; check out SPUtility.js on CodePlex! Original Post: This post builds off of my previous post about making fields read only. In this case, I needed to autopopulate the NewForm.aspx with a value that gets passed to the form via [...]]]></description>
			<content:encoded><![CDATA[<table class="information-bar" style="margin-bottom: 5px;" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td class="information-bar-icon-cell"><img src="http://kitmenke.com/blog/wp-content/uploads/2010/08/information.png" alt="" /></td>
<td><strong>August 20, 2010 Update:</strong> The code below has moved to be part of a bigger library&#8230; check out <a href="http://sputility.codeplex.com/">SPUtility.js</a> on CodePlex!</td>
</tr>
</tbody>
</table>
<p>Original Post:<br />
This post builds off of <a href="http://kitmenke.com/blog/2009/06/02/make-a-text-field-read-only-on-editformaspx-without-spd/">my previous post </a>about making fields read only. In this case, I needed to autopopulate the NewForm.aspx with a value that gets passed to the form via URL parameters.</p>
<p><span id="more-237"></span></p>
<p>In this case, the URL that gets passed in is something like:</p>
<pre lang="text" escaped="true">/Lists/ProjectTasks/NewForm.aspx?projectID=523</pre>
<p>I wanted to take the &#8216;projectID&#8217; URL parameter and autopopulate my Project ID field with this value.</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/03/projectid.png"><img class="alignnone size-full wp-image-238" title="Project ID field" src="http://kitmenke.com/blog/wp-content/uploads/2010/03/projectid.png" alt="" width="258" height="32" /></a></p>
<p>Additionally, we will make this field Read Only so that they can&#8217;t change the value. Lastly, do this all without SharePoint designer or C# code.</p>
<p>Stick the following code in a Content Editor on your NewForm.aspx or EditForm.aspx. (Remember you can get to edit mode by appending ToolPaneView=2 on the end, like NewForm.aspx?ToolPaneView=2)</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script type=&quot;text/javascript&quot; src=&quot;/_layouts/1033/prototype.js&quot;&gt;&lt;/script&gt;<br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> CustomExecuteFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
    AutopopulateInputFromURL<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Project ID'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'projectID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> AutopopulateInputFromURL<span style="color: #009900;">&#40;</span>title<span style="color: #339933;">,</span>queryParamName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
   <span style="color: #003366; font-weight: bold;">var</span> inputs <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[title=&quot;'</span> <span style="color: #339933;">+</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">!=</span> inputs <span style="color: #339933;">&amp;&amp;</span> inputs.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
        <span style="color: #003366; font-weight: bold;">var</span> input <span style="color: #339933;">=</span> inputs<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
        <span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> location.<span style="color: #660066;">href</span>.<span style="color: #660066;">toQueryParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>queryParams <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> queryParams<span style="color: #009900;">&#91;</span>queryParamName<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
           input.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span>queryParams<span style="color: #009900;">&#91;</span>queryParamName<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
           <span style="color: #003366; font-weight: bold;">var</span> label <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;span&gt;&quot;</span> <span style="color: #339933;">+</span> input.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span><br />
           Element.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>before<span style="color: #339933;">:</span> label<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
           input.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
        <span style="color: #009900;">&#125;</span><br />
    <span style="color: #009900;">&#125;</span><br />
 <span style="color: #009900;">&#125;</span><br />
<br />
_spBodyOnLoadFunctionNames.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;CustomExecuteFunction&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div>
<p>Depends on <a href="http://www.prototypejs.org/">Prototype.js</a>.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=237&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/03/11/autopopulate-a-sharepoint-form-from-url/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Editing in SharePoint&#8217;s SPGridView</title>
		<link>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/</link>
		<comments>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 03:36:28 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=198</guid>
		<description><![CDATA[The goal of this post is to provide an easy to understand example of how to enable editing in an SPGridView. In this case, my datasource of choice is a SharePoint list. The way that I chose to implement editing in an SPGridView involved two classes: SimpleLogic &#8211; handles query and update operations SimpleSPGrid &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>The goal of this post is to provide an easy to understand example of how to enable editing in an SPGridView. In this case, my datasource of choice is a SharePoint list.</p>
<p>The way that I chose to implement editing in an SPGridView involved two classes:</p>
<ul>
<li><strong>SimpleLogic</strong> &#8211; handles query and update operations</li>
<li><strong>SimpleSPGrid</strong> &#8211; handles all of the setup for the ObjectDataSource and the SPGridView</li>
</ul>
<p>The main advantage for splitting the two classes is to separate all of the business logic into one class. Ideally, you should be able to completely change how the <strong>SimpleLogic </strong>class retrieves/updates data without changing the <strong>SimpleSPGrid</strong> code.</p>
<p><span id="more-198"></span></p>
<h2>The Setup</h2>
<p>In this example, our logic class is retrieving and updating data in a SharePoint list. My SharePoint list had three main columns: Title (text), Region (choice), and Total Sales (currency).</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-03-36.png"><img title="SPGridView Editing - SharePoint list" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-03-36.png" alt="SharePoint list" width="545" height="265" /></a></p>
<p>Now that I had some data to read from and write to, I was ready to create my logic class.</p>
<h2>The SimpleLogic Class</h2>
<p>The goal for the logic class was to expose all of the operations the gridview would need in order to read or update data:</p>
<ol>
<li>public DataTable Select()<br />
How do I get the data?</li>
<li>public List&lt;BoundField&gt; GetColumns()<br />
How do I display the data?</li>
<li>public void Update(Dictionary&lt;string, string&gt; data)<br />
How do I update the data?</li>
</ol>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SimpleLogic<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> LIST_NAME <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Example Sales Data&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> LIST_COLUMNS <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> VIEW_FIELDS <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> DATA_KEY_NAMES <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> SPWeb _currentWeb<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> SimpleLogic<span style="color: #008000;">&#40;</span>SPWeb currentWeb<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _currentWeb <span style="color: #008000;">=</span> currentWeb<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; DATA_KEY_NAMES <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DATA_KEY_NAMES<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LIST_COLUMNS <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LIST_COLUMNS<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LIST_COLUMNS<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LIST_COLUMNS<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Region&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LIST_COLUMNS<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; VIEW_FIELDS <span style="color: #008000;">=</span> GetViewFields<span style="color: #008000;">&#40;</span>LIST_COLUMNS<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> GetDataKeyNames<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> DATA_KEY_NAMES<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span> GetColumns<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span> fields <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fields<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>GetBoundField<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// we don't want the ID field to be editable so we make it readonly</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// readonly will mean a textbox to edit it will not be shown</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fields<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ReadOnly</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fields<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>GetBoundField<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fields<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>GetBoundField<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fields<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>GetBoundField<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> fields<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> BoundField GetBoundField<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// do not use SPBoundField (will not work with editing)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BoundField bf <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> BoundField<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bf<span style="color: #008000;">.</span><span style="color: #0000FF;">HeaderText</span> <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bf<span style="color: #008000;">.</span><span style="color: #0000FF;">DataField</span> <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> bf<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> DataTable <span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SPQuery q <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPQuery<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; q<span style="color: #008000;">.</span><span style="color: #0000FF;">ViewFields</span> <span style="color: #008000;">=</span> VIEW_FIELDS<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; q<span style="color: #008000;">.</span><span style="color: #0000FF;">Query</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;Where&gt;&lt;IsNotNull&gt;&lt;FieldRef Name='Title'/&gt;&lt;/IsNotNull&gt;&lt;/Where&gt;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SPList list <span style="color: #008000;">=</span> _currentWeb<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span>LIST_NAME<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SPListItemCollection items <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItems</span><span style="color: #008000;">&#40;</span>q<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> items<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataTable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetViewFields<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> columns<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder sb <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> field <span style="color: #0600FF; font-weight: bold;">in</span> columns<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sb<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendFormat</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;FieldRef Name='{0}' /&gt;&quot;</span>, field<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> sb<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> data<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SPList list <span style="color: #008000;">=</span> _currentWeb<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span>LIST_NAME<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> id <span style="color: #008000;">=</span> Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>data<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SPListItem item <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItemById</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>DISCLAIMER: When actually implementing the class above, you will probably need to add some sort of error handling. In order to provide a simpler example, the error handling has been omitted.</p>
<p>Once our logic class is functioning correctly, we can work on hooking it up to an SPGridView.</p>
<h2>The SimpleSPGrid Class</h2>
<p>The SimpleSPGrid class contains most of the guts that will probably be different to you. The first thing to notice is that it takes our SimpleLogic class as a parameter. This allows us to instantiate our logic class beforehand with any parameters that are needed, and then pass it into SimpleSPGrid to use.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SimpleSPGrid <span style="color: #008000;">:</span> CompositeControl<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> SimpleLogic _logic<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> ObjectDataSource _gridDS<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> SPGridView _grid<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> SimpleSPGrid<span style="color: #008000;">&#40;</span>SimpleLogic logic<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _logic <span style="color: #008000;">=</span> logic<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">sealed</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> CreateChildControls<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> GRIDID <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;grid&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> DATASOURCEID <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;gridDS&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ObjectDataSource<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> DATASOURCEID<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">TypeName</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SimpleLogic<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AssemblyQualifiedName</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">ObjectCreating</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ObjectDataSourceObjectEventHandler<span style="color: #008000;">&#40;</span>gridDS_ObjectCreating<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectMethod</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Select&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// to handle updates from the grid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">UpdateMethod</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Update&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">Updating</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ObjectDataSourceMethodEventHandler<span style="color: #008000;">&#40;</span>gridDS_Updating<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>_gridDS<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// create our grid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPGridView<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> GRIDID<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">DataSourceID</span> <span style="color: #008000;">=</span> _gridDS<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// link the grid to the ObjectDataSource</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">AutoGenerateColumns</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// must be false</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// generally the primary key field(s)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// these will be passed as an input parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">DataKeyNames</span> <span style="color: #008000;">=</span> _logic<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataKeyNames</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// add the column that will allow editing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CommandField command <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CommandField<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; command<span style="color: #008000;">.</span><span style="color: #0000FF;">ShowEditButton</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">Columns</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>command<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// add all of the columns in the datatable to the grid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// any column that is not readonly will be passed as an input parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>BoundField column <span style="color: #0600FF; font-weight: bold;">in</span> _logic<span style="color: #008000;">.</span><span style="color: #0000FF;">GetColumns</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _grid<span style="color: #008000;">.</span><span style="color: #0000FF;">Columns</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>column<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>_grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Consolidates all of the InputParameters (values from the grid)</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// into one dictionary of values to send to the update method</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">void</span> gridDS_Updating<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, ObjectDataSourceMethodEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> data <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>DictionaryEntry entry <span style="color: #0600FF; font-weight: bold;">in</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">InputParameters</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> value <span style="color: #008000;">=</span> entry<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">?</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">:</span> entry<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>entry<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #008000;">.</span><span style="color: #0000FF;">InputParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #008000;">.</span><span style="color: #0000FF;">InputParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;data&quot;</span>, data<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// When the ObjectDataSource is created, hook it up to the Logic class</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// (so that it uses the Logic class to make the Select, Update... calls)</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> gridDS_ObjectCreating<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, ObjectDataSourceEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #008000;">.</span><span style="color: #0000FF;">ObjectInstance</span> <span style="color: #008000;">=</span> _logic<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h2>Wrap up</h2>
<p>Now that all the hard work is done, we are ready to use the classes inside our web part. Inside the CreateChildControls of your webpart you would have the following code ( even though we have an SPWeb here, it should NOT be disposed):</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> CreateChildControls<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; SimpleLogic logic <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SimpleLogic<span style="color: #008000;">&#40;</span>SPControl<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContextWeb</span><span style="color: #008000;">&#40;</span>Context<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; SimpleSPGrid grid <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SimpleSPGrid<span style="color: #008000;">&#40;</span>logic<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This will produce the following grid!</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-01-15.png"><img title="SPGridView Editing - List Data" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-01-15.png" alt="List Data" width="587" height="260" /></a></p>
<p>And clicking edit&#8230;</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-02-00.png"><img title="SPGridView Editing - SPGridView Edit Mode" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-02-00.png" alt="SPGridView Edit Mode" width="485" height="217" /></a></p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=198&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Relative Dates in JavaScript</title>
		<link>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/</link>
		<comments>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 03:37:41 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=183</guid>
		<description><![CDATA[I was developing an input form for a search when I came across the need to allow the user to filter items using a date range. I had two input boxes where the user could enter a start and an end date. For some of the most common date ranges, I decided to create links [...]]]></description>
			<content:encoded><![CDATA[<p>I was developing an input form for a search when I came across the need to allow the user to filter items using a date range. I had two input boxes where the user could enter a start and an end date. For some of the most common date ranges, I decided to create links that could be clicked to auto-populate the start/end date textboxes. For example, searching for items that were created last week or last month. Using JavaScript&#8217;s Date object, I was able to put together some nice examples.</p>
<p><span id="more-183"></span></p>
<p>First, the setup. I needed two text boxes to hold the start/end dates and then wanted the user to click links to auto-populate them with some relative dates:</p>
<pre lang="html4strict" escaped="true">&lt;a href="javascript: void(0);" onclick="return setRelativeDate('today')"&gt;Today&lt;/a&gt;

&lt;label for="txtStartDate"&gt;Start Date:&lt;/label&gt;&lt;input id="txtStartDate" type="text" /&gt;
&lt;label for="txtEndDate"&gt;End Date:&lt;/label&gt;&lt;input id="txtEndDate" type="text" /&gt;</pre>
<p>Then to figure out how to calculate the dates using JavaScript. Here are the examples.. starting out easy with <strong>Today</strong>&#8216;s date. When creating a new Date object, it is automatically initialized to the current day and time:</p>
<pre lang="javascript" escaped="true">var today = new Date();
txtStartDate.value = getShortDateString(today);
txtEndDate.value = txtStartDate.value;</pre>
<p><strong>Yesterday </strong>is Today -1:</p>
<pre lang="javascript" escaped="true">var yesterday = new Date();
yesterday.setDate(yesterday.getDate()-1);
txtStartDate.value = getShortDateString(yesterday);
txtEndDate.value = txtStartDate.value;</pre>
<p><strong>This Week </strong>is a little more complicated. getDate() returns the day of the month (1-31) and getDay() returns the day of the week (0-6).</p>
<pre lang="javascript" escaped="true">var thisWeek = new Date();
// set the date to most recent Sunday
thisWeek.setDate(thisWeek.getDate() - thisWeek.getDay());
txtStartDate.value = getShortDateString(thisWeek);
// set the date to last week's Saturday
thisWeek.setDate(thisWeek.getDate() + 6);
txtEndDate.value = getShortDateString(thisWeek);</pre>
<p><strong>Last Week</strong> is pretty similar to this week. I think the hardest part for me is the function names getDate and getDay. I always was getting them confused and thought that they should have been more specific&#8230; like getWeekDay and getMonthDay or something.</p>
<pre lang="javascript" escaped="true">var lastWeek = new Date();
// set the date to last week's Sunday
lastWeek.setDate(lastWeek.getDate() - lastWeek.getDay() - 7);
txtStartDate.value = getShortDateString(lastWeek);
// set the date to last week's Saturday
lastWeek.setDate(lastWeek.getDate() + 6);
txtEndDate.value = getShortDateString(lastWeek);</pre>
<p>The main difficulty I had with <strong>This Month</strong> was how to figure out the last day of the month. Luckily, if you can figure it out by selecting the first of next month and then subtracting a day.</p>
<pre lang="javascript" escaped="true">var lastDayOfThisMonth = new Date();
// go to the next month
var nextMonth = lastDayOfThisMonth.getMonth() + 1;
lastDayOfThisMonth.setMonth(nextMonth);
// go to the last day of the previous month (this month)
lastDayOfThisMonth.setDate(0);
txtEndDate.value = getShortDateString(lastDayOfThisMonth);
lastDayOfThisMonth.setDate(1);
txtStartDate.value = getShortDateString(lastDayOfThisMonth);</pre>
<p>Notice how <strong>Last Month</strong> is actually easier because you can simply move backwards a month.</p>
<pre lang="javascript" escaped="true">var lastDayOfLastMonth = new Date(); // now
lastDayOfLastMonth.setDate(0); // last day of last month            
// set the end date first
txtEndDate.value = getShortDateString(lastDayOfLastMonth);
lastDayOfLastMonth.setDate(1);
txtStartDate.value = getShortDateString(lastDayOfLastMonth);</pre>
<p>The only issue I had with <strong>This Year</strong> was I didn&#8217;t realize that  setMonth(int) took a zero based month: 0 = January &#8230; 11 = December.</p>
<pre lang="javascript" escaped="true">var lastDayOfThisYear = new Date();
lastDayOfThisYear.setMonth(11); // December
lastDayOfThisYear.setDate(31);
txtEndDate.value = getShortDateString(lastDayOfThisYear);
lastDayOfThisYear.setMonth(0); // January
lastDayOfThisYear.setDate(1);
txtStartDate.value = getShortDateString(lastDayOfThisYear);</pre>
<p>Finally, to figure out <strong>Last Year</strong> I took advantage of the setFullYear(year,month,day) function to subtract one year.</p>
<pre lang="javascript" escaped="true">var lastDayOfLastYear = new Date();
// -1 means last year
// 11 means December and there always is a 31st of december
var thisYear = lastDayOfLastYear.getFullYear();
lastDayOfLastYear.setFullYear(thisYear - 1, 11, 31);
txtEndDate.value = getShortDateString(lastDayOfLastYear);
lastDayOfLastYear.setMonth(0); // January
lastDayOfLastYear.setDate(1); // 1st
txtStartDate.value = getShortDateString(lastDayOfLastYear);</pre>
<p>See all of it together in the <a href="http://kitmenke.com/blog/wp-content/uploads/2010/01/javascript_relativedates.html">complete demo</a>.</p>
<p>References:</p>
<ul>
<li><a href="http://www.w3schools.com/jS/js_obj_date.asp">JavaScript Date Object </a></li>
<li><a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">JavaScript Date Object Full Reference</a></li>
</ul>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=183&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint&#8217;s SPGridView, filtering, and apostrophes</title>
		<link>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/</link>
		<comments>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:10:43 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=138</guid>
		<description><![CDATA[May 20, 2010 Update If you are looking for a great example on how to create an SPGridView, check out Erik Burger&#8217;s blog: Building A SPGridView Control – Part 1: Introducing the SPGridView Building A SPGridView Control – Part 2: Filtering This post is really meant to supplement part 2 of Erik&#8217;s guide and address [...]]]></description>
			<content:encoded><![CDATA[<p><strong>May 20, 2010 Update</strong><br />
If you are looking for a great example on how to create an SPGridView, check out Erik Burger&#8217;s blog:</p>
<ol>
<li><a href="http://www.reversealchemy.net/2009/05/01/building-a-spgridview-control-part-1-introducing-the-spgridview/">Building A SPGridView Control – Part 1: Introducing the SPGridView</a></li>
<li><a href="http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/">Building A SPGridView Control – Part 2: Filtering</a></li>
</ol>
<p>This post is really meant to supplement part 2 of Erik&#8217;s guide and address values in the grid that include apostrophes when using filtering.</p>
<hr />
<p>The SPGridView is one of the most useful SharePoint controls. You can use it to do sorting, grouping, and filtering just like the out of the box List View Web Part does for regular lists and libraries. This makes it relatively easy to create a custom grid with your own data. Unfortunately, filtering with the SPGridView is a little quirky, especially if your data could potentially contain apostrophes.</p>
<p><span id="more-138"></span>Essentially, all you need to do is set a few quick properties to enable filtering on the SPGridView. (<a href="http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/">see the great tutorial on Reverse Alchemy for more information</a>)</p>
<pre lang="csharp" escaped="true">// Filtering
grid.AllowFiltering = true;
grid.FilterDataFields = ",Name,Region,Total Sales";
grid.FilteredDataSourcePropertyName = "FilterExpression";
grid.FilteredDataSourcePropertyFormat = "{1} = '{0}'";</pre>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-04-35.png"><img class="alignnone size-full wp-image-144" title="2009-09-03 14 04 35" src="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-04-35.png" alt="2009-09-03 14 04 35" width="502" height="170" /></a></p>
<p>However, what happens if you have an apostrophe for the value in one of your filters (for example filtering on the name of O&#8217;Reilly). Eventually, you will end up with a filter of:</p>
<pre>Name = 'O'Reilly'</pre>
<p>If this is the case, when you attempt to filter using that value you will get the error:</p>
<pre>Syntax error: Missing operand after 'Reilly' operator</pre>
<p>(<a href="http://stackoverflow.com/questions/1351578/spgridview-data-and-correct-method-of-ensuring-data-is-safe">See the question asked by Moo on StackOverflow</a>)</p>
<p>So how do you prevent the apostrophes from messing up your filter?</p>
<pre lang="csharp" escaped="true">protected override void OnPreRender(EventArgs e)
 {
     if (!string.IsNullOrEmpty(_gridDS.FilterExpression))
     {
         _gridDS.FilterExpression = string.Format(
             _grid.FilteredDataSourcePropertyFormat,
             _grid.FilterFieldValue.Replace("'", "''"),
             _grid.FilterFieldName);
     }
     base.OnPreRender(e);
 }</pre>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-07-58.png"><img class="alignnone size-full wp-image-145" title="2009-09-03 14 07 58" src="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-07-58.png" alt="2009-09-03 14 07 58" width="372" height="86" /></a></p>
<p>Where _gridDS is an ObjectDataSource (you must use an ObjectDataSource as opposed to setting the DataSource SPGridView property) and _grid is your SPGridView.</p>
<p>The solution is relatively simple&#8230; but what is happening behind the scenes? Actually, pretty much the same thing but without the replace. The SPGridView looks up your ObjectDataSource using the <em>DataSourceID</em> property. Once it has your ObjectDataSource, it then sets the property specified in FilteredDataSourcePropertyName (FilterExpression) to be the filter. Once you understand that behind the scenes, all it really is doing is setting the FilterExpression on your datasource, it is pretty easy to override the incorrect filter with a correct one.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=138&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a SharePoint Alert with different EventTypes</title>
		<link>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/</link>
		<comments>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 01:55:00 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=108</guid>
		<description><![CDATA[I recently ran into a problem creating alerts in a web part for the current user. After the alert was added, no matter what I set the SPAlert&#8217;s EventType to, it always defaulted to All. I finally figured out a way around this problem thanks to a helpful post by erwin at sharepointology. The workaround [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem creating alerts in a web part for the current user. After the alert was added,  no matter what I set the SPAlert&#8217;s EventType to, it always defaulted to All. I finally figured out a way around this problem thanks to a helpful post by <a href="http://www.sharepointology.com/development/how-to-create-alerts-programmatically/">erwin at sharepointology</a>.</p>
<p><span id="more-108"></span></p>
<p>The workaround involves setting the eventtypeindex in the SPAlert Properties. Since I designed my web part to be configurable, an admin is able to specify the following web part properties</p>
<ul>
<li>SPEventType WPPAlertEventType<br />
(Add, All, Delete, Discussion, Modify)</li>
<li>SPAlertFrequency WPPAlertFrequency<br />
(Daily, Immediate, Weekly)</li>
<li>int WPPAlertTimeHour<br />
(the hour of the day 0 &#8211; 23, only applies to Daily and Weekly alerts)</li>
<li>int WPPAlertTimeDayOfWeek<br />
(the day of the week 0 &#8211; 6, only applies to Weekly alerts)</li>
<li>bool WPPSendConfirmationEmail<br />
(whether or not to send the email saying that they were signed up for the alert)</li>
</ul>
<p>Unfortunately, you can&#8217;t just convert WPPAlertEventType and put it in &#8220;eventtypeindex&#8221; because SPEventType&#8217;s enums were defined to have wacky binary values.</p>
<pre lang="csharp" line="1" escaped="true">// Create an Alert for this List
SPAlert alert = currentUser.Alerts.Add();
alert.AlertType = SPAlertType.List;
alert.AlertTemplate = list.AlertTemplate;
alert.AlwaysNotify = false;

// DOESN'T WORK SETTING THE EVENT TYPE
//alert.EventType = (SPEventType)WPPAlertEventType;

// you must set the eventtypeindex property
switch (WPPAlertEventType)
{
     case SPEventType.All:
          alert.Properties["eventtypeindex"] = "0";
          break;
     case SPEventType.Add:
          alert.Properties["eventtypeindex"] = "1";
          break;
     case SPEventType.Modify:
          alert.Properties["eventtypeindex"] = "2";
          break;
     case SPEventType.Delete:
          alert.Properties["eventtypeindex"] = "3";
          break;
     case SPEventType.Discussion:
          alert.Properties["eventtypeindex"] = "4";
          break;
     default:
          break;
}

alert.AlertFrequency = WPPAlertFrequency;

// get the config for daily/weekly alerts

// the hours can be anything from 0 to 23
bool alertTimeHourIsValid = (WPPAlertTimeHour &gt;= 0 &amp;&amp; WPPAlertTimeHour &lt;= 23);
int alertTimeHour = alertTimeHourIsValid ? WPPAlertTimeHour : DEFAULT_WPPAlertTimeHour;

// the day of the week can be anything 0 to 6 (Sunday = 0 - Saturday = 6)
bool alertTimeDayOfWeekIsValid = (WPPAlertTimeDayOfWeek &gt;= 0 &amp;&amp; WPPAlertTimeDayOfWeek &lt;= 6);
int alertTimeDayOfWeek = alertTimeDayOfWeekIsValid ? WPPAlertTimeDayOfWeek : DEFAULT_WPPAlertTimeDayOfWeek;

switch (WPPAlertFrequency)
{
     case SPAlertFrequency.Daily:
          DateTime dailyAlertTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, alertTimeHour, 0, 0);
          alert.AlertTime = dailyAlertTime;
          break;
     case SPAlertFrequency.Immediate:
          break;
     case SPAlertFrequency.Weekly:
          DateTime weeklyAlertTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, alertTimeHour, 0, 0); ;
          weeklyAlertTime = weeklyAlertTime.AddDays(alertTimeDayOfWeek - (double)weeklyAlertTime.DayOfWeek);
          alert.AlertTime = weeklyAlertTime;
          break;
     default:
          break;
}
alert.List = list;
alert.Title = string.Format("{0} ({1} {2})", list.Title, WPPAlertEventType, WPPAlertFrequency);
bool sendConfirmationEmail = WPPSendConfirmationEmail;
alert.Update(sendConfirmationEmail);</pre>
<p>References:</p>
<ul>
<li><a href="http://www.sharepointology.com/development/how-to-create-alerts-programmatically/">How To Create Alerts Programmatically</a></li>
</ul>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=108&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoIt3 script to auto resize windows</title>
		<link>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/</link>
		<comments>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 14:58:09 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AutoIt3]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=103</guid>
		<description><![CDATA[One thing that bugs me all the time is when a window doesn&#8217;t remember the position that it was resized or moved to. Although it is more of a nuisance than anything else, I decided to write a little AutoIt3 script to automatically resize my Remote Desktop windows to be the certain place and size that [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that bugs me all the time is when a window doesn&#8217;t remember the position that it was resized or moved to. Although it is more of a nuisance than anything else, I decided to write a little AutoIt3 script to automatically resize my Remote Desktop windows to be the certain place and size that I prefer them to be in.</p>
<p><span id="more-103"></span></p>
<p>The following script will find any windows that have &#8220;Remote Desktop&#8221; in the title and resize them to be their maximum height and width. In fact, I tweaked it a little bit so that the window actually falls outside of the screen. This way I have more screen real estate for the desktop that I&#8217;m working in and I will also be able to quickly move between windows on my desktop.</p>
<pre lang="autoit" escaped="true">;********************************************************************************
; Filename: maximize_window.au3
; Author: Kit Menke
; Date: July 30, 2009
; Description:
;   Resizes any window matching a certain search string to the given dimensions.
;   Useful for Windows you find you have to constantly resize.
;********************************************************************************

; any window that contains the following string will be resized
$windowTitleContains = "Remote Desktop"

; only match exact title names in this script
Opt("WinTitleMatchMode", 3)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

; the new dimensions of the window to be resized to
; top left corner (x,y) coordinates
$winX = -4
$winY = -29
; the window's new width and height
$winWidth = 1024 - $winX*2
$winHeight = 768 - $winY

; get the list of windows and the string you want to check for
$var = WinList()

For $i = 1 to $var[0][0]
  ; Only display visble windows that have a title matching our search string
  $windowTitle = $var[$i][0]
  $containsTitle = StringInStr($windowTitle,$windowTitleContains)
  If $windowTitle &lt;&gt; "" AND IsVisible($windowTitle) AND 0 &lt;&gt; $containsTitle Then
    ResizeWindowWithExactTitle($windowTitle)
  EndIf
Next

Exit

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func ResizeWindowWithExactTitle($winTitle)
    If WinExists($winTitle) Then
        WinMove($winTitle, "", $winX, $winY, $winWidth, $winHeight)
    EndIf
EndFunc</pre>
<p>I then set up a little CMD file to call my au3 file (assumes AutoIt3.exe is in the same directory as your script, but you can obviously make this be whatever you want):</p>
<blockquote><p>AutoIt3.exe maximize_window.au3</p></blockquote>
<p>And then I have a shortcut to that CMD file on my quicklaunch that I can call whenever I need to resize my windows.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=103&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
