Query String URL & Data View Web Parts (Part 3 of 4)

In the last two posts of this series, I showed you how to use the MOSS Enterprise out of box web part called the Query String (URL) Filter.  This post will show you how to accomplish the same thing, but without MOSS.  This entails using the data view web part.  I’ll use the same example of a project details page.  The query string will be used to pass the project ID to each of the data view web parts on a page.

Even if you DO have MOSS, another good reason to use data view web parts for mash-ups, is that redundant column that you’re connecting to.  You know how when you’re creating web part connections, the only columns available for the connection are the ones that are being displayed in the web part? When data view web parts are used, ALL list fields are available in the connection, not just the displayed ones!

Here’s how to configure each web part in SharePoint Designer, to use a Query String:

  1. Create a blank web part page, and open it in SharePoint Designer.  Insert a data view web part, we’ll just start with the issues list.  Again, this is using the same project details example, so please read my last post about it.
  2. In the Data View menu in the toolbar, click Parameters.
  3. There will already be one parameter.  Add a new Query String parameter, called “ProjParam”, like this:
    ch7[9]
  4. In the Data View menu in the toolbar, click Filter.
  5. Create a filter where the ProjID field is equal to the new parameter [ProjParam]:
    ch7[10]
  6. Save the page.  Make sure there are a couple of items in the list, each with a ProjID associated with them.  Open the web part page in the browser and test the query string.

The trick is that now you use the URL in order to pass the project number to this web part.  This is supposed to be a project mash-up, so add all of the associated lists to the page as data view web parts, and repeat steps two through five on each one.

The URL to the page will now end with the page name.aspx?Project=2

That red number is unique to each project.  In my previous post, I showed how to create the workflow that generates that project details URL for each new project.  This screenshot shows that this list is automatically filtered by issues that have a ProjID field equal to one, because of the URL.

ch7[11]

In summary, here’s a brief comparison:

Query String (URL) Filter Web Part
  • Out of box web part
  • No SharePoint Designer needed
  • MOSS Enterprise version needed
Data View Web Part With Query String
  • SharePoint Designer data view web part creation needed
  • More complex setup
  • Can be done in just WSS, without MOSS

Note that you can still create all data view web parts, and still use the Query String URL Filter Web Part.  This combination method will let you get rid of all of the redundant columns, in this case the ProjID… with the ease of use of the out of box query string URL filter web part.

Here are the other parts in this series:

Advertisements

43 comments

  • Great set of posts, very useful. Question though: in this post you filtered an issue list on project “2” – what about issues that cross multiple projects? Is it possible to capture those as well? I have a similar problem where I have lists that have some items related to only a single project, but some items are related to all projects. How could I create a project specific page that captures both uniquely identified issue items and also those issue items related to all projects?

    Like

  • hsin2002@gmail.com

    Hi Its really good idea of using dataview webpart. I am looking to extract data from a list which is created by current logged in user .How do I do that in data view web part?. Any help appreciated..

    Like

  • hsin, Just add a filter in your regular sharepoint view where: Created By is equal to [Me] DVWP not necessary, but you could create the same kind of filter there also.

    Like

  • I’m probably missing something here, but this is my current understanding: if you specify more than one parameter, you MUST specify values for each. If you do not, then you get nothing. For example, if you say you are going to supply values for ‘fair’ and ‘appt’ but you only specify ‘fair’, you’ll get nothing, because you have not specified “all” or “don’t care” for ‘appt’. How does one specify a value of “all” or “don’t care” for a query string parameter? You would expect something like ‘*’, but that doesn’t work for me…

    Like

  • Thanks for posting. Very usefull

    Like

  • Hi Is it possible to connect the data view part to document library dynamically. Let us say I have 10 doc libraries having common content types like incoming letter. I have created a dataview web part to view only incoming letter content type for 1 of the document library. I have inserted that web part on a new page. I want to use the same page for other document libraries also. Basically I want the dvwp to connect dynamically to doc library whose name is sent as query string

    Like

  • mrbroschat, Good question, I’m not sure. rzp, No, I don’t think there’s a way to send the name of the library as a query string. Well, maybe you could try greating a Linked Data source as a merge of all those libraries, and somehow do something to filter them by a portion of the URL to each item?

    Like

  • I have been successful in setting up dataview webpart and query strings to pull information related to a list item based on the item ID on some lists. In some cases though, the query string URL picks the item ID but the destination page does not show the relevant data. I have been looking for posts that might help me with this issue but could not find something. Can you please help?

    Like

  • Hi Laura, Great series of posts! Your blog has helped me solve a lot of different problems on SharePoint. I was wondering if you know of a way to pass a date parameter from a query string to the default value of a Date Filter Web Part. It would be fantastic if that were possible. Thanks a bunch, Lee

    Like

  • Lee, Hi, no I can’t seem to get that to work wih a date filter web part. Doesn’t make any sense, though.

    Like

  • you will need to have a javascript on the page to add the date to the end of the url (ex: ….?reportDate=07/14/2011 ) then reload the page with the date at the end and have a dataview pick up the param (using custom param) note: if your list contains a date field, it will not work as it will be comparing date & Time stamp within the dataview. ONly way I was able to get around this is to make the date field a text field. If anyone knows how to parse out the date within the dataview query param you will have the status of uberSP developer!

    Like

  • Hi Laura, nice blog, but is there anyway to pass multiple params in the querystring? It appears the dataview only can handle 1 querystring param… also on the date, have a javascript add the date to the end of the url and reload the page. the dataview will pull the date out of the url. thank you

    Like

  • Hi Laura, Thanks for the article! I want to be able to return to a parent page after entering data in a child page, and have the original filter settings in effect on the data views on the parent but show the new data as well. Can this be done as a variation on your methods? (I don’t have Enterprise Ed, but I am using SP Designer 2007.)

    Like

  • Al, use the &source to redirect them to a certain page after they’ve filled out a form. Read my post called “May the &Source be with you”.

    Like

  • Hi Laura, I have created a custom display page. When I go back to the list and click to view the 7th item from that list for example, the display view always opens on the first item of the list. How do I filter to get to the display view wish to see?

    Like

  • Thanks. This helped me quite a bit.

    Like

  • Miya, You’d have to create a parameter in your new custom display data view web part. Go to parameters and create one called ID. Then, create a filter on the web part where the ID of the list item is equal to the ID parameter.

    Like

  • Hi Laura, Thanks for sharing helpful articles. I am using query string to filter dataview but what should I do to show all. I have Glossary Dataview with items grouped by Strating Alphabets (A, B, C..). There are hyperlinks of all Alphabets which when clicked shows specific items. But how to show all items?? Hope you understand what I tried.

    Like

  • Hi Laura, your post has been really helpfull,however i am having difficulty filtering the contents of a dataview webpart that is based in a custom SQL query in a database through a query string. I have tried all that you say but what happens is i get a empty data set (no results). Here is what ia have done ConnectionString=”Data Source=sql01\crm;User ID=********;Password=********;Initial Catalog=EFC_MSCRM;” ProviderName=”System.Data.SqlClient” SelectCommand=”SELECT AccountId , Name , new_office . new_countryidName , account . new_organisationmainofficeid , new_office . new_officeid FROM account LEFT JOIN new_office ON account . new_organisationmainofficeid = new_office . new_officeid WHERE [New_EFCMembership] = ‘1’ AND new_countryidName = ‘@Param1′” and i have also set and the page is url?code=DE&country=Germany Any help would be appreciated Thanks

    Like

  • Hi Laura, I’ve been pondering the concept of building pages of content, such as for a product which has regional variations, on the ‘fly’ from a list with ‘Multiple Lines of Text’ columns each shown in a separate List View on the page and filtered via a Form Web Part with a drop down list. Whilst the use of Data Views was sort of successful, I don’t have MOSS Enterprise, I managed to find a solution to the problem of having to have the column to be filtered show in a List View Web Part, this link – http://moblog.bradleyit.com/2010/05/hide-filtered-column-on-sharepoint-list.html – provides code to hide the column by searching for the one with the ‘filter’ graphic in the header and hiding it. Now I can use OOTB List View Web Part and a customised Form Web Part, along with the piece of code mentioned above, to create a page of information based on the selection from the Form Web Part. Thanks for the help in pointing me in the right direction.

    Like

  • DV, Maybe you can just make the “all items” link take them to another page, where there’s no filter, and then when they click a letter, it takes them back to the page with the query string on it?

    Like

  • Confused in Colorado

    I have set up the DVWP and the parameters. It works just fine when I manuall add a value to the URL. I’m trying to set this up to work with the List Item Menu custom action Navigate to URL. I want to pass a field value from the list item (other than {itemID}. Title would be fine. I tried MYPAGE.ASPX?SCODE={title} but that did not work. How can I pull from the current record one of the field values? Do I have to resort to javascript (which I can only do by stealing someone else’s example)? It seems this should be relatively straightforward and OOTB. I can’t believe I’m the only person that wants to take some value from a list item and pass it to a filter. All help much appreciated.

    Like

  • Dear “confused”, Please let me know which step that you’re referring to, and if not referring to any step, please let me know what you’re trying to “pull” the title from and TO. A simple web part connection may be the answer. I just don’t understand what you’re asking.

    Like

  • Confused in Colorado

    Thanks, Laura. Let’s see if I can do this without pictures. I have a task list “A” in SharePoint. For simplicity’s sake, let’s say it has four fields: ID (or ItemID), Field1, Field2, Field3. Let’s also assume that the three fields are custom columns I’ve created for the list (so I can retrieve the actual column name later on). I also have an independent SQL Table “B” that I write to using an external list and present back to users via DVWP. What I want to do is put a custom action on the List Item Menu that reads the value of Field1 (or any other) from the current item in LIST A, passes it as a parameter to a page with a filtered data view of TABLE B. Net result would be an instant search of TABLE B based on the (non-unique) identifier value in FIELD1 of LIST A. Obviously, I have all the parts working separately – a web part filter of the DVWP already works, but requires navigation to a secondary page and entry of the filter value. I’m trying to save my users significant time and effort as this would be a function they would use constantly. When I go into SPD and create a new Custom Action, the “Navigate to form” option is pre-selected with the default edit form and a parameter of: …aspx?ID={ItemID} I’m hoping there is a similar syntax that would allow me to read the value of Field1 and pass it along as a parameter to a filter web part (using the third type of action: Navigate to URL), but simply trying ={Field1} doesn’t seem to work. Here’s the actual parameter portion of the URL I’m trying: .aspx?scode={survey code} When I replace “{Survey code}” with an actual value, it works just fine. I’ve also set up the Title field to mirror this custom field, but that doesn’t seem to help. I can’t use the task ID, as there are multiple tasks related to a particular code I want to filter the table on. Alternately, I’ve currently enabled the Show List Item Menu and Show Link to View selections in the list view “Common xsl:value-of Tasks” properties menu/dialog box in SPD. If there isn’t an easy answer to the above effort, then I am sure we could hire someone to write code to add a third option to replace the Show Link to View feature with the desired behavior. However, that would be a last resort. If I’ve managed to cloud the issue even further, contact me at (remove the plus signs) war+ren@mark+et+pay.com Thanks again for all the wonderful info you provide.

    Like

  • Hi Confused in Colorado, Wow, that’s pretty complex, custom, and very specific with lots of great details. I’d have to work with you one on one to figure something like that out to see if it’s possible out of box. You can use the Contact Us form on our home page, if you’re interested in talking to us about our rates and how that would work.

    Like

  • Confused in Colorado

    Thanks again, Laura I am coming to the conclusion that this isn’t functionality available out of box. {ItemID} and {ListID} are available as parameters for forms, but I don’t think any other columns from a list are (without adding some javascript or rewriting core components). So I’ve decided on a simpler, though less elegant route: I’ll add a column to the list and add a routine to the OnChange workflow I have to update this field every time the item is changed (overkill, but it ensures that the paremeter matches the current value of the desired field). The field will be a hyperlink tag surrounding a single “H” (for History, the name of the SQL table I’m referencing). The value of the parameter can then be read from a field in the current item using the String Builder in SPD and added to the URL text. It won’t be accessible from the List Item Menu, but the single-click functionality I want my users to have will be there. It is less elegant because it means I have to add the column to every view where I want the functionality — which is why it is only a single letter, to conserve real estate. A custom action on the LIM would be the preferred solution, but you do what you have to do.

    Like

  • Hi -,
    Thanks for you post. I’m so newbie in SharePoint 2010…
    I’m tried to follow your steps.. but still no luck.

    My aim is to display on the target page the same record from source page. I used “new form item” for page 1 and “edit form item” for page 2. I also used the navigate to page.. and set the parameter value to ID. I added your steps that would filter the data in page 2. but no luck.. below is the URL and parameter i used:

    * /CreateLeaver2.aspx?@ID={@ID} – this is the url i used with param.
    * I used the word “ID” to declare query string which looks like this:NAME = Param1
    Query String: id

    ** the result when I navigate the page2 is EMPTY.
    Please help..

    Thanks so much in advance.

    Like

  • By using the query string uRl and dataview webpart, will the page get refresh for displaying data.
    Actually I dont want my page to get refresh at time of displaying the data.

    Like

  • Hello Laura,
    Thanks for you post!
    the query string received parameter type datetime in the format:
    yyyy-mm-dd

    Beso!

    Like

  • Van,
    Read my other post here: http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=107 I think it will help with what you’re trying to accomplish.

    Like

  • In my case, I am trying to create a custom new form for a list. I have already tested passing a parameter in (step 3 in your example), which works fine, because I successfully get that parameter value to display on the form itself.

    When I try to use the URL parameter in a filter on a joined (joined, not merged) list, the Data Source Properties window does not save my filter (step 5 in your example) or my column choices. Has anyone else experienced this issue?

    Like

  • Hi, Laura!
    A common problem with this approach is: if we don’t specify a filter value on the query string, the list will display nothing. Any way to go around this?
    Thanks!

    Like

  • About my previous question: my Twitter handle is @rjperes75.

    Like

  • If you don’t have Enterprise Edition of Sharepoint, is there another way to accomplish the functionality of the Query String Webpart? I’ve been watch your HR Onboarding Videos, where you are building the Dashboard, and I oly have Foundation version of sharepoint 2013.

    Like

  • Hi Jared, I wrote a blog post about how to do that:
    https://wonderlaura.com/2011/01/24/pass-default-value-from-a-web-part-page-to-a-new-item/

    Steve,
    You’d have to open the view in SharePoint Designer, and add a parameter and filter from there.

    Ricardo,
    That’s been a common question among all of the comments in this blog, and I haven’t personally figured out a way.

    Like

  • Hi Laura,
    I was looking for a way to mask the parameter value in the URL and somehow got your insightful post.

    Could you please help me?

    I want to convert this URL
    http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=99

    To something like
    http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=xys4sy

    where the ID itself is masked or hashed. I work in Healthcare and so cannot display any identifying information on URL.

    Thanks!
    Ken

    Like

  • As far as tweaking these types of solutions to do that, I’m not sure how, but I do know that with cross-site publishing in 2013, the query string (thing it’s filtered by) is automatically hidden by default. Ben Niaulin wrote a post with step by step instructions. http://en.share-gate.com/blog/migrate-sharepoint-2013-what-is-product-catalog

    Like

  • Hello Laura, You are a SharePoint Goddess. I LOVE your work and we are all very grateful.

    I was wondering if you could let me know.
    Like an old Classic ASP page where a detail page is created by reading off a querystring variable. I would like to be able to populate a “newsletter” page by taking the items of a row ( BY ID via querystring ) and fill n the “header”, the body and the image from that row. Reading all your great info I’m not sure how to apply it for this instance. What web parts do I use to pull in the header, the body and for the image I’d assume it’s “image” but what more how do I grab that row info that page and feed it into those parts?

    I’m certain you’re flooded but I’m feeling a little lucky today.

    Thank you and kudos to you.

    Mike

    @blackbeardUSA

    Like

  • Mike,
    It sounds like you could create a parameter in your form that you want to fill in, and then create a web part connection that sends the row of data, and instead of “filter”, choose “parameter”, and then it will send it to the consuming form. I guess you’d have to send each value to the new form like this? https://wordpress.com/post/wonderlaura.com/544

    Like

  • Hi..

    As you pass this in URL page name.aspx?Project=2 that work for me also… i would like to pass two parameter at same time…
    for Exmp : page name.aspx?Project=2&VideoID=4

    Is it possible with data web part?

    Thanks,

    Like

  • Can you use other operators other thn “=” in the settings?

    Like

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s