<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Powlo's SharePoint Treats</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/powlo/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/powlo/feed.xml</link>
    <description>Friendly SharePoint banter and code nuggets from Paul Robinson</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:23:11 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Adding custom SharePoint Toolbar and ToolbarButtons in code</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/adding-custom-sharepoint-toolbar-and-toolbarbuttons-in-code</link>
      <pubDate>Sun, 24 Feb 2008 18:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2008/02/24/adding-custom-sharepoint-toolbar-and-toolbarbuttons-in-code/</guid>
      <description><![CDATA[Part 3: Extending your web part to include toolbars
SharePoint toolbars use user controls (.ascx...]]></description>
      <content:encoded><![CDATA[<H6 class=posthead-minor>Part 3: Extending your web part to include toolbars</H6>
<P>SharePoint toolbars use user controls (.ascx files) to control HTML rendering and layout. This is great if you have an ASPX page to use them on (in fact, you can base your efforts off one of the built in pages in the layouts directory). However, this presents an interesting challenge when you want to create toolbars through assembly code alone.</P>
<P>You'll notice there's no constructor for the two useful classes, Toolbar and ToolbarButton in the Microsoft.SharePoint.WebControls namespace. To get toolbars in your web part, you need to create a control using the Page.LoadControl method, pointing to the relevant user control and casting the results. It’s pretty simple:</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> CreateToolbar()
        {
            ToolBarButton toolbuttonGrouping </SPAN><SPAN style="COLOR: #000000">=</SPAN>
                <SPAN style="COLOR: #000000"> (ToolBarButton)Page.LoadControl(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">~/_controltemplates/ToolBarButton.ascx</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            toolbuttonGrouping.Text </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Show in Groups</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            toolbuttonGrouping.ImageUrl </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">/_layouts/images/TABGEN.gif</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            toolbuttonGrouping.Click </SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> EventHandler(toolbuttonGrouping_Click);

            ToolBar toolbar </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (ToolBar)Page.LoadControl(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">~/_controltemplates/ToolBar.ascx</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            toolbar.Buttons.Controls.Add(toolbuttonGrouping);

            Controls.Add(toolbar);
        }

        </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> toolbuttonGrouping_Click(</SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000"> sender, EventArgs e)
        {
            </SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> NotImplementedException();
        }</SPAN></DIV>
</PRE>
<P>This produces the following toolbar, when called from CreateChildControls:</P><IMG alt="Picture of SharePoint toolbar with one custom button" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/07/88/41/92/toolbar.png" original-url="http://blogs.msdn.com/photos/powlo/images/7884192/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/7884192/original.aspx"> 
<P>You can add buttons to the right using Toolbar.RightButtons.Controls collection if you fancy.</P>
<P>P.s. Sorry for the blogging gap – it’s been rather busy lately. At your request, I’m now putting together a full downloadable sample solution for SPGridView, SPMenuField and the Toolbar stuff, complete with grouping, paging and sorting. Check back in a couple of weeks.</P>]]></content:encoded>
    </item>
    <item>
      <title>SPGridView: Using Filter properties</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/spgridview-using-filter-properties</link>
      <pubDate>Tue, 15 May 2007 03:56:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/05/15/spgridview-using-filter-properties/</guid>
      <description><![CDATA[Great news everyone \o/ - a solution to setting an SPGridView filter has been researched and...]]></description>
      <content:encoded><![CDATA[Great news everyone \o/ - a solution to setting an SPGridView filter has been researched and documented <A href="http://www.sharepointblogs.com/bobsbonanza/archive/2007/05/14/filtering-with-spgridview.aspx" mce_href="http://www.sharepointblogs.com/bobsbonanza/archive/2007/05/14/filtering-with-spgridview.aspx">in this post</A> over at <A href="http://www.sharepointblogs.com/bobsbonanza/default.aspx" mce_href="http://www.sharepointblogs.com/bobsbonanza/default.aspx">Bob's SharePoint Bonanza</A> - well done that man!&nbsp; This should give you pretty much everything you need to build an SPGridView control which provides custom data binding, grouping, drop down menus and pagination - see <A href="http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx" mce_href="http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx">part 1</A> and <A href="http://blogs.msdn.com/powlo/archive/2007/03/23/Adding-paging-to-SPGridView-when-using-custom-data-sources.aspx" mce_href="http://blogs.msdn.com/powlo/archive/2007/03/23/Adding-paging-to-SPGridView-when-using-custom-data-sources.aspx">part 2</A> in this blog for an introduction.]]></content:encoded>
    </item>
    <item>
      <title>SPGridView: Adding paging to SharePoint when using custom data sources</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/spgridview-adding-paging-to-sharepoint-when-using-custom-data-sources</link>
      <pubDate>Fri, 23 Mar 2007 09:53:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/03/23/spgridview-adding-paging-to-sharepoint-when-using-custom-data-sources/</guid>
      <description><![CDATA[Part 2: Extending your SPGridview with paging controls
In Part 1: Using SPGridview, adding menus,...]]></description>
      <content:encoded><![CDATA[<H6 class=posthead-minor>Part 2: Extending your SPGridview with paging controls</H6>
<P>In <A class="" href="http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx" target=_blank mce_href="http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx">Part 1: Using SPGridview, adding menus, grouping and sorting</A> I looked at how to use an SPGridView from the ground up to bind to a custom DataSet. One of the features I omitted at the time was paging:</P>
<P>&nbsp;<IMG title="SPGridview showing paging controls" style="WIDTH: 591px; HEIGHT: 219px" height=219 alt="SPGridview showing paging controls" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/93/77/23/blog2_0.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1937723/original.aspx" width=591 mce_src="http://blogs.msdn.com/photos/powlo/images/1937723/original.aspx"></P>
<P><A class="" href="http://blogs.msdn.com/controlpanel/blogs/www.sharepointblogs.com/jason/archive/2006/10/23/14755.aspx" target=_blank mce_href="http://blogs.msdn.com/controlpanel/blogs/www.sharepointblogs.com/jason/archive/2006/10/23/14755.aspx">Jason Wang</A> already has a good post on the subject, but I’m going to continue my example with some pretty verbose code so hopefully things will just work first time for you.&nbsp; There is a gotcha – in order to display the paging tabs PagerTemplate needs to be set to null after the grid is added to the controls collection but before BindData is called; and you’ll need to give some extra consideration if you’re also using sorting.</P>
<P>In Part 3 by the way, I really want to cover filtering, but it’s proving tricky stuff, due to the way SPGridView is designed to process the filtering callback.&nbsp; At least I understand the problem - more on that shortly.</P>
<P><STRONG>Extending your code</STRONG></P>
<P>Pop this code just above oGrid.DataBind():</P>
<DIV><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Turn on paging and add event handler</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        oGrid.PageSize </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800080">3</SPAN><SPAN style="COLOR: #000000">;
        oGrid.AllowPaging </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;
        oGrid.PageIndexChanging </SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000"> 
            </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> GridViewPageEventHandler(oGrid_PageIndexChanging);
        oGrid.PagerTemplate </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Must be called after Controls.Add(oGrid)

        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Recreate current sort if needed</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortDirection</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000"> ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortExpression</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)
        {
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> We have an active sorting, so this need to be preserved</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">            oView.Sort </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortExpression</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">].ToString()
                </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortDirection</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">].ToString();
        }</SPAN></DIV></PRE></DIV>
<P>and add the event handler:</P>
<DIV><PRE><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> oGrid_PageIndexChanging(</SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000"> sender, GridViewPageEventArgs e)
        {
            oGrid.PageIndex </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> e.NewPageIndex;
            oGrid.DataBind();
        }</SPAN></PRE></DIV>
<P>The extra lines around sorting are important if you enabled sorting on the list in Part 1.&nbsp; Adding the paging means CreateChildControls() could now fire on a postback without a subsequent call to oGrid_Sorting().&nbsp; Depending on how you’re implementing state, this could mean the list switches back to being unsorted – giving the impression of duplicating or missing out entries if you sort before you page, so to speak.</P>
<P>&nbsp;Enjoy.</P>]]></content:encoded>
    </item>
    <item>
      <title>SPGridView and SPMenuField: Displaying custom data through SharePoint lists</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/spgridview-and-spmenufield-displaying-custom-data-through-sharepoint-lists</link>
      <pubDate>Sun, 25 Feb 2007 17:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/02/25/spgridview-and-spmenufield-displaying-custom-data-through-sharepoint-lists/</guid>
      <description><![CDATA[Part 1: Using SPGridview, adding menus, grouping and sorting
Click along to build this lovely Web...]]></description>
      <content:encoded><![CDATA[<H6 class=posthead-minor>Part 1: Using SPGridview, adding menus, grouping and sorting</H6>
<P>Click along to build this lovely Web Part, taking data directly from a standard .NET DataSet:</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/91/91/blog1_0.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1759191/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1759191/original.aspx"></P>
<P>SharePoint lists and libraries are great for storing almost everything, but what about if you need to display structured lists in SharePoint where the data is stored elsewhere?&nbsp; If you use Office SharePoint Server (MOSS), one great feature for this purpose is the Business Data Catalogue.&nbsp; However, if you only have Windows SharePoint Services (WSS), or need to dynamically construct data, chances are you'll end up needing to write a Web Part.</P>
<P>Web Parts give you some standard look and feel elements for free, like the ‘crome' or border, plus an ability to add your own properties to the properties grid.&nbsp; After that, you're pretty much on your own.&nbsp; Wouldn't it be nice if you could display your own data in a sexy SharePoint list?</P>
<P>SharePoint uses the Microsoft.SharePoint.WebControls.<B>SPGridView</B> control to display its own lists.&nbsp; This class inherits from System.Web.UI.WebControls.<B>GridView</B>, so the development experience to bind data, adjust columns, perform sorting etc is similar.&nbsp; The key difference is the control renders the grid in the SharePoint style - perfect.</P>
<P><STRONG>Create a Web Part</STRONG></P>
<P>Any blank Web Part will do - you could use the template provided by Visual Studio if you have the SharePoint SDK installed.&nbsp; My web part started out life like this:</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Runtime.InteropServices;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Web.UI;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Web.UI.WebControls;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Web.UI.WebControls.WebParts;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Xml.Serialization;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> System.Data;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> Microsoft.SharePoint;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> Microsoft.SharePoint.WebControls;
</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000"> Microsoft.SharePoint.WebPartPages;

</SPAN><SPAN style="COLOR: #0000ff">namespace</SPAN><SPAN style="COLOR: #000000"> ListMenuSample
{
    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> ListMenuSample : System.Web.UI.WebControls.WebParts.WebPart
    {
        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> SPGridView oGrid;
        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> TVData oDataset;
        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> DataView oView;

        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> PopulateDataset()
        {
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> TODO</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        }

        </SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">override</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> CreateChildControls()
        {
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> TODO</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        }

        </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> oGrid_Sorting(</SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000"> sender, GridViewSortEventArgs e)
        {
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> TODO</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        }

    }
}
</SPAN></DIV></PRE>
<P mce_keep="true"><B>Create the data source</B></P>
<P>In this example, we'll create and populate a dataset and use it for data binding.&nbsp; I want a list to keep track of who presents my favourite BBC current affairs programmes, so I'll design and populate a DataSet accordingly.</P>
<P>If you want to bind your SPGridView back to SharePoint data, that's simple too, check out this <A href="http://sharethispoint.com/archive/2006/09/05/UsingtheSharePointv3DataGridControlSPGridView.aspx">great article</A> from Share This Point.</P>
<P>My DataSet, TVProgrammeData has a single table, Presenters, comprising an int and two string columns:</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/11/blog1_1.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1758811/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758811/original.aspx"></P>
<P>We'll fill the DataTable from code, but obviously you'd want to pull this from somewhere, probably SQL, a filesystem, a web service or XML.&nbsp; Pop this into the PopulateDataset() method.</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> PopulateDataset()
        {
            oDataset </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> TVData();
            oDataset.Presenters.AddPresentersRow(</SPAN><SPAN style="COLOR: #800080">1</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Jeremy Paxman</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Newsnight</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            oDataset.Presenters.AddPresentersRow(</SPAN><SPAN style="COLOR: #800080">2</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Kirsty Wark</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Newsnight</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            oDataset.Presenters.AddPresentersRow(</SPAN><SPAN style="COLOR: #800080">6</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Bill Turnbull</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Breakfast</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            oDataset.Presenters.AddPresentersRow(</SPAN><SPAN style="COLOR: #800080">7</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Sian Williams</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Breakfast</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> plus a few more entries</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">        }</SPAN></DIV><DIV><SPAN style="COLOR: #000000"></SPAN>&nbsp;</DIV><DIV><SPAN style="COLOR: #000000"></SPAN></DIV></PRE>
<P><B>Render the Grid</B></P>
<P>Overriding CreateChildControls() is a good place to create your SPGridView and add it to the controls collection.&nbsp; You'll also need to bind up the columns and specify sorting.&nbsp; To give us magical sorting abilities, we'll bind to a DataView rather than directly back to the DataTable.&nbsp; Pop this into CreateChildControls():</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">override</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> CreateChildControls()
        {
            PopulateDataset();
            oView </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> DataView(oDataset.Presenters);

            oGrid </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> SPGridView();
            oGrid.DataSource </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> oView;
            oGrid.AutoGenerateColumns </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;
            oGrid.AllowSorting </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;
            oGrid.Sorting </SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> GridViewSortEventHandler(oGrid_Sorting);

            BoundField colName </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> BoundField();
            colName.DataField </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colName.HeaderText </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Presenter Name</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colName.SortExpression </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            oGrid.Columns.Add(colName);

            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Add the menu control here</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">
            BoundField colProgramme </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> BoundField();
            colProgramme.DataField </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">ProgrammeName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colProgramme.HeaderText </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Programme</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colProgramme.SortExpression </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">ProgrammeName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            oGrid.Columns.Add(colProgramme);
            
            Controls.Add(oGrid);
            oGrid.DataBind();

            </SPAN><SPAN style="COLOR: #0000ff">base</SPAN><SPAN style="COLOR: #000000">.CreateChildControls();
        }

</SPAN></DIV></PRE>
<P>Notice we specify the SortExpression to use, which together with AllowSorting enables users to order the results by clicking the columns headers.&nbsp; We need to perform the sort ourselves though, through the event handler; and we'll need to keep track of the sort direction in ViewState so we can flip it next time the user clicks the same header.&nbsp; I'm not sure my code is very elegant in this area, so leave a comment if you can think of a better way to do it in fewer lines of code.</P>
<P>Add this event handler:</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">      </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> oGrid_Sorting(</SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000"> sender, GridViewSortEventArgs e)
        {
            </SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000"> lastExpression </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">""</SPAN><SPAN style="COLOR: #000000">;
            </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortExpression</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)
                lastExpression </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortExpression</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">].ToString();

            </SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000"> lastDirection </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">asc</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortDirection</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)
                lastDirection </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortDirection</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">].ToString();

            </SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000"> newDirection </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">asc</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (e.SortExpression </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> lastExpression)
                newDirection </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (lastDirection </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">asc</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">) </SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">desc</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000"> : </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">asc</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;

            ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortExpression</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> e.SortExpression;
            ViewState[</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SortDirection</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">] </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> newDirection;

            oView.Sort </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> e.SortExpression </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> newDirection;
            oGrid.DataBind();
        }
</SPAN></DIV></PRE>
<P>If you build and deploy this web part, you should get something like this (see <A class="" href="http://blogs.msdn.com/powlo/archive/2007/02/25/deploying-and-debugging-web-parts.aspx" mce_href="http://blogs.msdn.com/powlo/archive/2007/02/25/deploying-and-debugging-web-parts.aspx">this post</A> for tips on the debugging process):</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/16/blog1_2.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1758816/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758816/original.aspx"></P>
<P mce_keep="true">&nbsp;</P>
<P>That looks alright, and it will adapt correctly if you apply different style sheets, themes or a new master page.&nbsp; But it's still not a very rich interface.&nbsp; How about if you wanted users to edit items, or get more detail.&nbsp; Umm, better add a menu.</P>
<P><B>Add a menu</B></P>
<P>It's worth pointing out about now that the documentation around this area is still in production - so I'm coding with a slight emphasis on experimentation for some of the property values - I'll point you to the official source when it's revised.</P>
<P>Anyway, SPMenuField is the class we need, and combines the roles of controlling the drop-down menu with the basic display work done by BoundField.&nbsp; Let's replace our boring colName column with a shiny menu that looks like this:</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/90/97/blog1_2b.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1759097/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1759097/original.aspx"></P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Replace the Name coloumn with a shiny menu</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">            colName.Visible </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> You could remove colName completely</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">
            SPMenuField colMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> SPMenuField();
            colMenu.HeaderText </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Presenter Name</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.TextFields </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.MenuTemplateId </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterListMenu</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.NavigateUrlFields </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">ID,PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.NavigateUrlFormat </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">do.aspx?p={0}&amp;q={1}</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.TokenNameAndValueFields </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">EDIT=ID,NAME=PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            colMenu.SortExpression </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            
            MenuTemplate presenterListMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MenuTemplate();
            presenterListMenu.ID </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">PresenterListMenu</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            MenuItemTemplate biogMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MenuItemTemplate(
                </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Read Biography</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">/_layouts/images/EawfNewUser.gif</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            biogMenu.ClientOnClickNavigateUrl </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">do.aspx?this=%EDIT%&amp;that=%NAME%</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">entry.ClientOnClickScript = "your javascript here";</SPAN><SPAN style="COLOR: #008000">
</SPAN><SPAN style="COLOR: #000000">            presenterListMenu.Controls.Add(biogMenu);

            MenuItemTemplate broadcastMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MenuItemTemplate(
                    </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Recent Broadcasts</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">/_layouts/images/ICWM.gif</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            presenterListMenu.Controls.Add(broadcastMenu);

            MenuSeparatorTemplate sepMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MenuSeparatorTemplate();
            presenterListMenu.Controls.Add(sepMenu);

            MenuItemTemplate favMenu </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MenuItemTemplate(
                   </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Add to Favorites</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">/_layouts/images/addtofavorites.gif</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);
            presenterListMenu.Controls.Add(favMenu);

            </SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.Controls.Add(presenterListMenu);
            oGrid.Columns.Add(colMenu);
</SPAN></DIV></PRE>
<P mce_keep="true">Tip: You can have a poke around the standard icon collection and pick some suitable images from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES</P>
<P>SPMenuField serves two purposes - it configures the hyperlink you follow if you click on the item directly and, optionally, links to a snazzy dropdown menu.</P>
<P>This <A href="http://sharepointsolutions.blogspot.com/2006/10/quick-site-settings-adding-sub-menus_16.html">great post at SharePoint Solution Blog</A> gives a good overview of how to extend the Admin interface with custom menus.&nbsp; However, the difference with custom menus on list items is that you're not creating one - you're creating one for each list item, and your menu handling routine needs to know which item you clicked in.</P>
<P>Fortunately, there are a few ways to achieve with.&nbsp; First we setup colMenu to pass in the required parameters when you click on the main item hyperlink:</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/18/blog1_3.PNG" original-url="http://blogs.msdn.com/photos/powlo/images/1758818/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758818/original.aspx"></P>
<P>Here, NavigateUrlFields is a comma-separated list of data bound items we want to use in the URL.&nbsp; Then we replace placeholders starting at {0} with the items in sequence.</P>
<P mce_keep="true"><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/21/blog1_4.png" original-url="http://blogs.msdn.com/photos/powlo/images/1758821/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758821/original.aspx"></P>
<P>Next, we need to decide how to respond to clicks on the drop-down menu.&nbsp; We have two options here - build a click URL similar to the one above, or use our own javascript.&nbsp; We might have a third option to do a sexy postback to an event in the code behind, but I can't decipher exactly how to use that yet - keep tuned.</P>
<P>The URL way uses a modification in syntax but essentially the same principle as above.&nbsp; This time we name the data fields we want and then consume them within % signs on the menu items:</P>
<P><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/26/blog1_5.png" original-url="http://blogs.msdn.com/photos/powlo/images/1758826/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758826/original.aspx"></P>
<P>Let's finish off for now by adding some grouping (and a few more presenters):</P><PRE><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><SPAN style="COLOR: #000000">            oGrid.AllowGrouping </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;
            oGrid.AllowGroupCollapse </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;
            oGrid.GroupField </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">ProgrammeName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            oGrid.GroupDescriptionField </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">ProgrammeName</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
            oGrid.GroupFieldDisplayName </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Programme</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;
  </SPAN></DIV><DIV><SPAN style="COLOR: #000000"><IMG src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/01/75/88/25/blog1_6.png" original-url="http://blogs.msdn.com/photos/powlo/images/1758825/original.aspx" mce_src="http://blogs.msdn.com/photos/powlo/images/1758825/original.aspx"></SPAN></DIV><DIV><SPAN style="COLOR: #000000">&nbsp;</SPAN></DIV><DIV><SPAN style="COLOR: #000000">&nbsp;</SPAN></DIV><DIV><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">Next: <A class="" href="http://blogs.msdn.com/powlo/archive/2007/03/23/adding-paging-to-spgridview-when-using-custom-data-sources.aspx" mce_href="http://blogs.msdn.com/powlo/archive/2007/03/23/adding-paging-to-spgridview-when-using-custom-data-sources.aspx">Part 2: Extending your SPGridview with paging controls</A></SPAN><SPAN style="COLOR: #000000"></DIV></PRE>
<P>Leave a comment if you've found this useful, and particularly if there's anything else you'd like to see added.</P>
<P>Enjoy.&nbsp; </SPAN></P>]]></content:encoded>
    </item>
    <item>
      <title>MOSS Enterprise Search - 16 things you might not know</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/moss-enterprise-search-16-things-you-might-not-know</link>
      <pubDate>Sun, 25 Feb 2007 17:08:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/02/25/moss-enterprise-search-16-things-you-might-not-know/</guid>
      <description><![CDATA[Hello everybody \o/ - a few bits and pieces you might find useful when designing and deploying...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">Hello everybody \o/ - a few bits and pieces you might find useful when designing and deploying Enterprise Search based on Office SharePoint Server 2007 - most of these tips can be credited to some Partner training delivered by Morten Schioldan.</P>
<P><B>Really interesting things</B></P>
<UL class=unIndentedList>
<LI>On document libraries which support approval, users might be able to search and view abstracts for unpublished content which they would otherwise not be able to see. This happens if the crawler account has permission to view drafts, which is separate from any security trimming which will be applied. Using an account with only reader permissions would prevent this, but conversely a user with rights to see draft content could only search content from the last published version. Since the files share a URL it's either one or the other - a decision to be made by your customer.</LI>
<LI>Keyword search has moved from implicit OR to implicit AND as standard, although this can be configured on calls through the web service. Additionally, <A href="http://blogs.msdn.com/nigelbridport/">Nigel Bridport</A> pointed out to me that if you use the Advanced Search, which in effect creates a SQL query, you can specify to AND or OR your requests as well as wildcard your keywords, etc.</LI>
<LI>Only a full crawl will re-index ASPX files. Therefore, if you have removed documents from a document library, the library may still appear in the results if you search for the document name after an incremental crawl. <A href="http://blogs.msdn.com/grahamtyler/">Graham Tyler</A> spotted this one.</LI></UL>
<P><B>Capacity</B></P>
<UL class=unIndentedList>
<LI>There is a tested recommended maximum of 4 SSPs per farm, and a hard limit of 20.</LI>
<LI>The tested recommended maximum is 50 million documents across all content sources in an index. Since you can have only one index server per Shared Services Provider, the recommended approach for more capacity is to add another SSP. There is no supported way to union the results. Don't forget BDC items count to your total.</LI>
<LI>There is a hard limit of 500 start addresses per content source. If the default content source is full, additional new sites will not have their start addresses registered (anywhere), so you'll need to add them manually to another content source, or change the default content source.</LI>
<LI>Information about the size of search indexes and search databases relative to corpus size is due to be released on Technet shortly.</LI></UL>
<P><B>Configuration and topology</B></P>
<UL class=unIndentedList>
<LI>Since the Indexer crawls a Web Front End for SharePoint content, in a load balanced scenario, any of the Web Front End servers could get hit. You can override this and specify a single WFE for the Indexer to use. In this case, you could exclude this from the load balancer and have it as a dedicated WFE for indexing.</LI>
<LI>Query and Index roles can run on the same server. However, to add extra Query servers, the Indexer must run alone. E.g. you would scale out from Query+Index on one server to Index on one server and Query on two servers.</LI>
<LI>Collapsing your WFE and Query roles onto the same server can improve query performance, especially when custom security trimmers are used on the WFEs to iterate over the results.</LI>
<LI>Architectures can be mixed between roles (e.g. 32bit WFE, 64bit Indexer) but not in the same role.</LI>
<LI>64bit is recommended for the Indexer, but most custom IFilters, like Adobe PDF, don't support this new platform just yet.</LI></UL>
<P><B>Crawling and Querying</B></P>
<UL class=unIndentedList>
<LI>The default maximum file size the Indexer will download and parse is 16mb. This is a registry entry on the Indexer - one to update if customers deal with large PowerPoint slidedecks etc.</LI>
<LI>Search term word stemming is off by default. You can enable this in the Core Search Results web part, but it may skew the new improved ranking mechanism.</LI>
<LI>Search usage reports gather data from client side asynchronous JavaScript when a user selects a result from the results page. Therefore, reports don't show search terms used through the API or the Query Web Service.</LI>
<LI>It's kind-of obvious, but forms authentication to external websites is not supported for crawling. </LI></UL>]]></content:encoded>
    </item>
    <item>
      <title>Deploying and debugging Web Parts</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/deploying-and-debugging-web-parts</link>
      <pubDate>Sun, 25 Feb 2007 17:07:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/02/25/deploying-and-debugging-web-parts/</guid>
      <description><![CDATA[When it comes to deploying and debugging your Web Part, you're spoilt for choice.&nbsp; My...]]></description>
      <content:encoded><![CDATA[When it comes to deploying and debugging your Web Part, you're spoilt for choice.&nbsp; My preference is to package the web part into a cab file, creating and including a manifest XML and DWP file.&nbsp; This should be familiar ground to seasoned web part developers, but an assortment of good MSDN and community content is available on this topic.&nbsp; Then deploy into the SharePoint mist with stsadm. 
<P><STRONG>Debugging Tip 0 - Setting up your environment</STRONG></P>
<P>Check your environment is configured per <A href="http://msdn2.microsoft.com/en-us/library/ms916837.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms916837.aspx">Debugging Web Parts</A>, the most important changes in web.config being</P>
<P>&lt;SafeMode MaxControls="50" CallStack="true"/&gt;</P>
<P>and</P>
<P>&lt;customErrors mode="Off"&gt;</P>
<P><STRONG>Debugging Tip 1 - Getting meaningful exceptions</STRONG></P>
<P>If you're using Visual Studio, add debug symbols to your cab as a project output group along with your Primary Output to enable a lovely debugging experience.&nbsp; Even if you don't attach a debugger, helpful exceptions should bubble up to the page.</P>
<P><STRONG>Debugging Tip 2 - Speeding up debugging round trips</STRONG></P>
<P>If you're working alone developing a web part and find you need to run an iisreset repeatedly to see your code changes (maybe you've deployed to the GAC), remember that your assembly isn't loaded into memory until it's first used. I set off an iisreset as soon as I'm done with a debugging session (so iisreset gets on with it as I'm changing my code).&nbsp; As long as you update/redeploy your assemblies before refreshing the page, you'll see the changes and you won't have to wait.</P>]]></content:encoded>
    </item>
    <item>
      <title>Fix for error: Outlook could not create the work file</title>
      <link>https://docs.microsoft.com/archive/blogs/powlo/fix-for-error-outlook-could-not-create-the-work-file</link>
      <pubDate>Mon, 01 Jan 2007 12:39:00 GMT</pubDate>
      <dc:creator><![CDATA[Paul Robinson]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/powlo/2007/01/01/fix-for-error-outlook-could-not-create-the-work-file/</guid>
      <description><![CDATA[A friend of mine, Chris Fenly from Waterstons, got in touch today about a weird problem he was...]]></description>
      <content:encoded><![CDATA[<P>A friend of mine, Chris Fenly from Waterstons, got in touch today about a weird problem he was having with two Windows XP SP 2 machines running Office 2003.&nbsp; Opening Word or Outlook generated the error "Outlook could not create the work file. Check the temp environment variable."&nbsp; It's an issue which a few people seem to have according to Internet search engines.&nbsp; Anyway, before I could be of any help, he'd fixed it.&nbsp; </P>
<P>On his machines HKCU\Software\Microsoft\Windows\Current Version\Explorer\User Shell Folders\Cache was pointing to %windir%\temp.&nbsp; He changed it to C:\Windows\temp and all was well.&nbsp; I didn't ask where his %windir% variable was pointing at the time - I wish I had now.</P>]]></content:encoded>
    </item>
  </channel>
</rss>