1,761 articles and 13,715 comments as of Sunday, November 14th, 2010

Tuesday, November 2, 2010

SharePoint: Integrate ASP.net controls with Forms – Part 5: Force Selection within Drop Down List

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

So Close!

You may have noticed the Drop Down control has a bug. When you visit the page, an item is already selected but the EditForm isn’t displayed for that item. The best I can tell is the value for the Drop Down is set before the EditForm is ready to accept a connection. Don’t worry though; we can fix it with just a few tweaks to the control.

First we must select/click/highlight (pick your pleasure) the Drop Down List so we can open the Tag Properties for this control. With anything you set out to do, there is always more than one way to get it done. You can select the control and then Click Task Panes, Tag Properties; or you can simply double click on the Drop Down List.


The settings we are interested in are:

  • AutoPostBack
  • ToolTip
  • AppendDataBoundItems
  • DataSourceID
  • DataTextField
  • DataValueField
  • Misc – Items

Notice that some of these properties are highlighted in blue. This happens when you customize a setting for this control. Remember checking the AutoPostBack option in Step 1? Since some of these properties have already been set, we don’t need to worry about them. I’ve listed them above so when you want to deep dive into the inner workings, you’ll have a good base to start from.

Ready, Set, Config!

Let’s set the ToolTip first. This gives a visual indicator to the user of the page. When you hover over the Drop Down List, a notification will appear. These are extremely useful when trying to give simple tips to your users. For this property, we are allowed to type our message directly into the box to the right.


You’ll notice some properties work differently. Some only give you a True/False selection. By using these controls, you’ll become more familiar with these properties and how each one works. AppendDataBoundItems is a prime example of why it’s necessary to become familiar with these controls. It’s difficult to decipher at first glance what this really does. From trial and error, I’ve found out that it actually solves our problem. Let’s set it to True. By doing that, the items that we add in the next step will be appended to the Drop Down control. If that’s still confusing, after you complete all of the steps and get the page working, go back and set this property to False. The last property we have to set is under the Misc heading and it’s called Items. This allows us to manually add items to select from our Drop Down List. Click the ellipses on the right of Items, so we can add an item.


This brings up a rather odd looking dialog, but once you know what it’s doing for you, you’ll get that raise from your boss! Click Add and then configure this item to:

  • Enabled:True
  • Selected:True
  • Text:Select a document…
  • Value:Select a document…


It’s important to note, the property Value plays a very important part here. Remember in Step 3, we configured the parameter to filter our EditForm when the ID equals the ID of the SPDatasource. Since we’ve set the Value here to: Select a document…, there’s no possible way the Drop Down List will filter to an EditForm. With this in mind, it’s definitely possible to *NOT* have your Drop Down bound to an SPDatasource and manually insert items with values. You could then filter based off of whatever you’d like to. Do I recommend it? No, because it’s just as easy to bind this control to a list and update the values there. It’ll keep you from having to dip into SPD just to add more functionality down the road.

HOORAY!

Guess what? We’ve done enough to merit saving the page. While we are at it, go ahead and open this page. Do you notice anything different? At this point, you should have: Select a document…, as your initial selection. With this in place, your users are now forced to make a selection and aren’t stuck wondering why your Drop Down isn’t working when the page is initially loaded.


If you’ve followed along from the beginning, we have just finished building a Drop Down List that’s automatically populated with Items the current user has created. Upon selecting an Item, an EditForm appears and allows for easy manipulation of metadata. There’s a nagging question to all of this: What else can I do with these techniques? That’s an awesome question because using this techniques; you are able to add functionality to your page that you simply can’t find anywhere else in SharePoint. I’ll leave it up to you to post comments on how you are using this or how it could be used. I definitely have some ideas for follow-up posts and have a project coming up where I’m going to be using this extensively. I’d still love to hear from you guys though, so don’t be shy in the comments!

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»
 

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!