title: Add a checkbox to each row of a ListViewWebpart
body: <p>I'm working on a WSS 3 site that has a ListViewWebpart displaying various columns.</p>
  
  <p>I need to add a checkbox to each row and a button to the header that will perform a server side action for the selected rows.</p>
  
  <p>Do I need to make my own custom webpart or can the ListViewWebpart support checkboxes?</p>
  
  <h2>Adding checkboxes to each row</h2>
  
  <p>I've found a post <a href="http://murugangs.blogspot.com/2007/12/checkbox-in-listviewwebpart.html" rel="nofollow">Checkbox in ListViewWebpart</a> which suggests </p>
  
  <blockquote>
    <p>...to add a checkbox, to select multiple
    listitem, in the custom list, declare
    a xml string as follows.</p>
  </blockquote>
  
  <pre><code>&lt;Field Type="Computed" ReadOnly="TRUE" Name="ListItemSelection" DisplayName="Select" Sortable="FALSE" Filterable="FALSE" EnableLookup="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ListItemSelection"&gt;
  &lt;FieldRefs&gt;
  &lt;FieldRef Name="ID" /&gt;
  &lt;/FieldRefs&gt;
  &lt;DisplayPattern&gt;
  &lt;HTML&gt;&lt;![CDATA[&lt;input type="checkbox" ]]&gt;&lt;/HTML&gt;
  &lt;HTML&gt;&lt;![CDATA[LItemId="]]&gt;&lt;/HTML&gt;
  &lt;Column Name="ID" HTMLEncode="TRUE" /&gt;
  &lt;HTML&gt;&lt;![CDATA["/&gt; ]]&gt;&lt;/HTML&gt;
  &lt;/DisplayPattern&gt;
  &lt;/Field&gt;
  </code></pre>
  
  <blockquote>
    <p>and call the
    list.Fields.<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcollection.addfieldasxml%28v=office.12%29.aspx" rel="nofollow">AddFieldAsXml</a>(“xml
    string”);. Include this as a first
    column in your custom list’s view.</p>
  </blockquote>
  
  <p>I'm assuming the latter part requires a SPList. E.g. </p>
  
  <pre><code>SPList list = SPContext.Current.Web.Lists["MyList"];
  list.Fields.AddFieldAsXml(stringWithXmlFieldDefinition);
  </code></pre>
  
  <h2>Adding a button to the header row</h2>
  
  <p>One option for the header button is a <a href="http://blog.thekid.me.uk/archive/2008/04/29/sharepoint-custom-actions-in-a-list-view-webpart.aspx" rel="nofollow">CustomAction</a>. This should create a button in the toolbar.</p>