1,804 articles and 14,635 comments as of Monday, March 7th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, September 30, 2010

SharePoint: Integrate ASP.net controls with Forms – Part 1: Use a SP Datasource to push values to a drop-down menu control

Note from Mark Miller: When I first saw this article from Matt I said “Slow down there, cowboy. We don’t do .NET development here, remember?” Then I looked it over and realized what he is doing is within Sharepoint Designer. Don’t let the title scare you off. Give it a try and tell him what you think. — Mark

Guest Author: Matt Bramer

I’d like to start this post of with giving credit where credit is due: ASP.NET Controls Filter the Data View. Finding this post was key to the end solution. Within this post, I’d like to elaborate on some of the things you should know, and make it a bit more end-user friendly. Also, over the next few articles, I’m going to show you how to make an interactive Edit Form for a Document Library using this ASP.net control.

I’m interested, where do I start?

Glad you asked. Typically, what I do is crack open SPD (SharePoint Designer) and create a blank .aspx page. It’ll look similar to this:



The next step is to add a table to the page. This will be the base for all of the content and will allow us to have a place to add controls and Web Part Zones. I’ll talk more about in a later post.

To add this click on Table from the menu bar and then click: Insert Table. The next dialog box allows you to control how many columns and rows your table has. For this example, I’m only going to have 2 of each. All of the other options, I am using the default settings.



Now that we have a place for our ASP.net control, we’ll need to add it to the page. You can do that by clicking on Insert from the menu bar, select ASP.net controls, then choose Dropdown List. Here’s a screenshot of what that will look like:



It’s a good time to note, that you cannot add this control to a Web Part Zone. Try with all of your might, it doesn’t work.

This looks cool but what do I do with it?

We have to populate this Dropdown list with data. For this example, we’re going to create a DataSource from my Shared Documents Library. To do this, we have to click on Task Panes, DataSource Library. From this pane, we can click on the Shared Documents menu and select Insert Data Source Control.



Once we have the DataSource inserted to the page, we need to configure our Dropdown List (I personally like to change the tag properties of this control, but you don’t have to.). To do that, click on the control. A tiny chevron appears and when we click on that, a fly out menu appears. Add a checkmark to: Enable AutoPostBack and then select the option to Choose Data Source.



We want to wire this control up to our Shared Documents library. Select LinkFileName for the display field and select ID for the value field.




This will populate the Dropdown List with all of the names of your documents that are in the Shared Documents library. Selecting the ID for the data field will tell the page what value the selection should be set to. Using ID, we’ll be able to get accurate results later on.

It still doesn’t look like much?!?

Now we’ll add the master page to this custom page we have built so far. Click on Format, Master Page, Attach Master Page.


I’ve chosen my default master page. If you have custom master pages, now is the time you would want to use that instead. All we have to do now is save this page. I already have an Apps Document Library setup, so that’s where I’ll be storing my page. Here’s the end result:



The next article, I’m going to walk through adding a Web Part Zone and then a DVWP (Data View Web Part) as an Edit Form. If you want me to add some things along the way, feel free to post a comment!

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

12 Responses to “SharePoint: Integrate ASP.net controls with Forms – Part 1: Use a SP Datasource to push values to a drop-down menu control”
  1. Marcel Meth says:

    I would **love** to do many of the things I do with InfoPath using straight aspx pages. Then I can easily use WSS instead of the enterpriuse version of SharePoint. SO here are a few things that I am interested indoing:

    1. Hide/show entire sections of controls, based on the inputs given in a key control (Say a checkbox)
    2. Prefill Controls or labels based on who the user is.
    Maybe I have a list of information that belongs to each user, I would ike to get this information to prefill the form.
    3. Like to be able to get inbformation from secondary data sources: Sharepoint Lists and Web Services

  2. rachael says:

    Excellent!! I’ve never managed to get this to work before.
    Is it possible to populate the dropdown box using a webservice instead of a SP list?

  3. Matt B. says:

    Nice ideas guys… Keep them coming.

    @Marcel ~ I spoke with Mike Greene a lot about InfoPath and what you could use it for. Essentially, we came up with the same thoughts: You can do everything you can in InfoPath in .aspx pages. I’ve never used InfoPath and that’s why I started asking around. In later posts, I actually plan on trimming this drop-down control based off of the currently logged in user and filtering an DVWP Edit Form.

    @Rachael
    First thought is sure, why not? ;-P Stay tuned though… I’ll look into that.

  4. Great work, Matt! Keep it up.

    @Marcel
    1. jQuery can doing your hiding/showing.
    2. I’m working on a Mileage Reimbursement solution right now. I have user information that I’m able to access from a web service. I’ve set up the default page to check for an employee number in the querystring. If it doesn’t find one, it gets the Emp# for the CurrentUser and refreshes itself with that in the querystring.

    If the user has never created a mileage record, the page shows a webpart (that’s hidden by default) with their manager, director, department, and location prefilled. They click OK and the record is saved and the page refreshes with a mileage dashboard, a quick entry form (to add mileage records one trip at a time), and a tabbed history below that.

    3. For getting information from other sources, look closely at Marc Anderson’s SPServices. I use it for getting at multiple lists.

    Hope that helps you down the right path.

    Blessings,
    Jim Bob

  5. Frank says:

    Good article and nice way to keep everyone coming back to EUSP. Waiting for the end so I can put it all together.

  6. Richard says:

    Thanks Matt, you helped me out a lot today with this article. Thanks to Mark Miller as well!

Trackbacks

Check out what others are saying about this post...
  1. SharePoint Kaffeetasse 204…

    SharePoint 2010 Connecting SharePoint 2010 Farms with Service Applications: Part 1 Connecting SharePoint…

  2. [...] this post doesn’t make any sense, please read over the first post in this series. I’m going to keep building on each post and then tying them together at the [...]

  3. [...] you’ve followed along from Step 1, then the first SelectCommand that you’ll find is the one we’ll need to update. The [...]

  4. [...] 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. [...]




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!