1,732 articles and 13,291 comments as of Tuesday, October 19th, 2010

Thursday, October 14, 2010

SharePoint: Integrate ASP.net controls with Forms – Part 3: Update the DVWP Form using a Drop-Down

Guest Author: Matt Bramer
http://mattbramer.blogspot.com

Now that we have a good base, we can move this form along into something useful. Essentially what we are going to do is have the Drop Down List display the correct Edit Form for that document. Let’s get to it, shall we?

Create a parameter

First we need to open up the DVWP’s Common Data View Tasks, by clicking on the chevron again and then clicking on Parameters…


This will open up a confusing dialog box, if you’ve never used this before. Here’s a screenshot:


I’ve found that generally, there will always be a ListID already setup for you. Sometimes, there are others, but I haven’t seen consistency with other parameters. I leave these alone. There’s no need to disturb Mother SharePoint. She knows best! What we need to do is create a New Parameter. After clicking on New Parameter, you get an opportunity to name the parameter. I always name the parameter something I can instantly recognize. I’ve named mine: ddlSharedDocs. The prefix: ddl stands for Drop Down List and since this parameter is going to be used for the Shared Documents library, it makes sense to use SharedDocs. The next piece is to set the Parameter Source to Control. After doing that another selection appears called: Control ID.

I click the what, with the what, and then…. What does all of this actually do? If you remember, we configured the SPDatasource to display the LinkFileName (code for the column: Name) and to have a value of ID. That simply means display all of the names, but when you select a name the value equals the ID related to the document. You’ll see why this is so important in the next step.


Sweet, still no code!

If you save the page and open it, the control STILL doesn’t do anything when you select a new value… Yep, that’s right, one final step. We need to wire up the Parameter to the ID of the DVWP Form. Don’t worry; it’s not as hard as it sounds. Let’s dive into the Common Data View Tasks dialog again and click on Filter. Now all we have to do is select ID and make it Equal to ddlSharedDocs. Here’s a screenshot of what it should look like:


Press OK and now let’s see what this page does. Wwithin this page, we have a Drop Down List that’s populated from an SPDatasource. This data source is pulling the Names of all of the documents within the Shared Documents Library. When you click on a name within the Drop Down List, the DVWP Form for that document appears because it’s filtered by ID. Now we can easily modify metadata that relates to these documents. Here’s a screenshot of what it looks like:


Sure there’s datasheet view for bulk updating records, but I’m showing a simple example of what is possible. There are many, many cool things you can do with parameters. This only covers a very small portion. Here’s a great link that gives ideas on how you *could* use them: http://www.sharepointnutsandbolts.com/2008/07/spdatasource-every-developer-friend.html. It’s ok if this look like Klingons to you. I’m still learning new tricks from this page myself and refer to it all the time. When you start using Parameters, Controls, and SPDatasources, it’s really opening up a whole new set of tools; “Middle-Tier Power Tools”. I invite you to learn more about how to use them. We can trade notes…

But wait, there’s more?

Of course there is, there’s always something more you *could* do… Within these articles, we’ve not touched code one bit. Now it’s time to drizzle a few tiny tweaks into the mix. Don’t be shy, not only will you impress your users, you may impress your boss enough to get a raise. That’s a true story by the way. In the next article, I’ll show you how to trim the Drop Down List to only show documents created by the user viewing the page. I’ll also show you how to configure the Drop Down List to force a selection. As always, post a comment if you’d like me to explore something we *could* do.

Guest Author: Matt Bramer
http://mattbramer.blogspot.com

Matt Bramer works as a Systems Admin in the construction industry.  He has been working with Search Server Express since 2008 and frequently blogs about his findings at http://mattbramer.blogspot.com.  Matt often posts to Stump the Panel and likes to tweet about his IT projects on Twitter (@iOnline247).

View all entries in this series: SharePoint: Integrate ASP.net controls with Forms»
 

Please Join the Discussion

5 Responses to “SharePoint: Integrate ASP.net controls with Forms – Part 3: Update the DVWP Form using a Drop-Down”
  1. spevilgenius says:

    If only I were really allowed to use SPD this would be great! I have to do it all in Visual Studio! Great Post!

  2. George W says:

    Arggh!
    This is great except that the values for your field DocCategory would be more at home in a field named DocReviewStatus.

    • Matt Bramer says:

      I left out building the Doc Library on purpose. I’m more or less showing you what you can do with these controls. I’ll leave building the foundation to you… You know better than I do what your solution should be. For my solution, I have about 10 docs that are categorized: I’ve been slacking
      I don’t think anyone would ever use that, so I didn’t write about it.

      Maybe next time, I’ll add building the list/library. Sometimes, though, I find that to be too related to my solution and not exactly what you are looking for. I like seeing theory and building my solution around those techniques. #4 is on it’s way; Stay tuned…


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!