Sunday, September 2, 2012

TIP: Hiding DataView Web Part Checkboxes

Introduction

Its frequently the case that when you insert a Listview or Dataview web part onto a SharePoint 2010 page, you don't want the "item checkboxes" to appear.  The reason being that they can take up valuable space on the page and they can sometimes skew the appearance and placement of items in the list.  Removing this checkbox is easily accomplished, and there is plenty of discussion providing details for removing them by adding the "TabularView" parameter to the  <View > sub node of the <XmlDefinition> node and setting this parameter to "FALSE" [1, 2, & 3] like so:
<View Name=... TabularView="FALSE"...
However, there really is no need to do any code modification.  All you really have to do is to make a settings change to the list's application page, and then re-insert the Dataview web part; or make the settings change before you even insert the DataView web part, and then you won't have to fiddle with the web part again.

Discussion

By default, a view of a list, on the list's application page, provides checkboxes (shown at leftmost column) enabling multiple list rows to be selected.  By default, the tabular view is enabled.  This causes checkboxes to be displayed in the list. This allows, for example, for multiple list rows to be deleted simultaneously.  When you insert a DataView web part into a page, and then connect it to a list, that web part is configured per the list's default view. 

You can see this by looking at the <View> subnode of the dataview's <XmlDefinition> node.  This subnode incorporates all of the configuration parameters of the list's view.  Note the Name parameter: this is the object name of the view.  Listed here as subnodes of the <View> node, will be all of the fields displayed by the view.

Once you insert a DataView web part, SharePoint Designer takes a snapshot of the current view's properties, and then builds the web part code and inserts it into the ASPX page.  This is a static snapshot, not a dynamic one.  Once SharePoint Designer 2010 inserts the parameters for the web part, that's it: it doesn't do anything more.  The XSL for that web part is frozen.  Therefore, if you later make a change to the view that the web part connects to, such as changing the Tabular View parameter, in the view's Settings page, that change will not be reflected in the DataView web part.  To reflect that change in the web part, you will either need to adjust the parameter manually, by editing the code, or by re-inserting the web part.

Summary

This TIP showed you how to remove the checkboxes displayed next to items listed in a ListView or DataView web part.  Specifically, it discussed why the checkboxes appear and how to remove them either in code or in the list's view settings.  Happy Coding!

References

  1. XsltListViewWebPart – remove checkboxes
  2. Hide the item checkboxes and the select all checkbox in list view webparts
  3. Remove checkbox next to list items XSLT List view webpart Sharepoint 2010

3 comments:

Anonymous said...

I actually want to do the opposite, adding the tabular view to the list view web part. The checkbox disappeared after the site has been upgraded from 2010 to 2013. I tried the TabularView = "TRUE" but it didn't work, any thoughts? Thanks!

Al said...

You can set this through the list View settings page: 1) got to the list; 2) click the "..." ellipsis and then select Modify this view; 3) scroll down to the Tabular View group; 4) ensure that "Allow individual item checkboxes" is checked; 5) click OK.

Anonymous said...

It's a custom list view web part, so it has to be done in SP Designer. I added TabularView = "TRUE", it never gets to be saved.