Thursday, April 10, 2008

SharePoint - Default Value for connected DataView webpart

Scenario (MOSS 2007):

I have a listview (standard format) connected to a dataview. Connection is source web part and provides row to target web part, which gets filter values from.

In essence, if you click on an item in the list view, I want to see a few particular fields in the dataview.

In this particular case, the listview was a list of open projects or tasks for members of our network group, and the comments were too long to display - it made the rows gy-normous and basically unreadable - also making the page stretch so long you had to scroll to eternity to get to the bottom of the list.

The culprit field was "comments" so we removed it from showing on the list. Now the title of the project, along with the comments, could be shown in the top webpart which was the dataview getting filter value from the listview.

Problem: When a user first opened the list, the first item (ID=1) would show the comments. It was as if the default value for the page was the first record. We did not want this behavior.

Solution: After some research on the web, I found musings about sending parameters in querystring. I also noticed that when I selected an item, the page was refreshed and a querystring parameter was being sent as: &selecteditem=... (number ID of task I clicked).

  1. Add a parameter:
    • Under Common Data View Tasks (click the little boxed arrow on the right of the dataview when hovering over the dataview), then click on Parameters... link.
    • Select New Parameter, I named it RecID, set Parameter Source to Query String, Query String Variable to SelectedID, Default Value: 0
    • Click out of the Parameter menu and select Filter: in the Common Data View Task pop-up.
    • Click in the field name, choose field (for my list I choose ID), left the comparison as Equals, then Value my new parameter of [RecID] was in the pull-down list
Now the default filter value for my dataview webpart was set to nothing (no 0 record existed in my list).

No comments: