Section 7.1. Using Lists to Gather Data


Table 7-2. Option settings for Add Item view

7.1. Using Lists to Gather Data

If you've read this far, you're probably already familiar with the simple Announcements and Contacts lists. You can enter data in those lists by choosing New Item or Edit in Datasheet from the list toolbar. For simple lists, Edit in Datasheet often works best because you can create new items simply by tabbing to the next row. For lists that contain long text fields or other types of data, New Item is often a better choice.

When you choose New Item, SharePoint displays the New Item page ( NewForm.aspx ). New Item displays text boxes, drop-down lists, or other controls for each field in the list. Required fields are indicated by an asterisk, as shown in Figure 7-1.

animal 7-1. Adding new items to a list

The New Item page is the data-entry form for the list. You complete the fields on the page, and choose Save and Close to store the data in the list. To exit without saving, choose Go Back to List or just navigate to another page. SharePoint generates the fields you see on the New Item page based on the types of columns found in the list, as shown by Figure 7-2.

animal 7-2. Using column type to create controls

There are a couple things you need to know about the column types:

  • Multiline text columns can include formatting.

  • Choice and Lookup column types generate drop-down lists.

  • Numeric, currency, and date/time columns validate the data entry as that type. For example, you can't enter five in a numeric column.

  • Calculated columns are read-only, don't appear on the New Item page, and can't be totaled in a standard view.

Even though lists seem very simple, you can do some significant data entry tasks with them. The following sections walk you through creating a list for collecting and categorizing expenses. I used it to figure out how much I spent building my boat, but you can modify it for other uses.

7.1.1. Building a Lookup Table

Before creating a data entry list, you need to consider what types of multiple-choice options members might need to enter. You can provide multiple-choice options in a list through either a Choice or Lookup column type, as appropriate:

  • Use Choice to display options that aren't likely to change.

  • Use Lookup to display a dynamic set of options from another list. Lookup columns can also link to data in other lists, so they are a good way to include details for complex options.

Lookup tables can't span web sites. If you are creating a list for use in multiple web sites, use the Choice type rather than the Lookup type.


The list in this tutorial categorizes expenses for a boat-building project. When I started the list I wasn't sure of all the categories I'd need, so I created a lookup table list for the main ones I could think of, then I added new categories as needed.

To create the lookup table list:

  1. From the SharePoint site, choose Create Lists Custom List. SharePoint displays the New List page.

    1. Choose Edit in Datasheet.

    2. Enter the items as shown in Figure 7-3.

    3. Choose Show in Standard View to commit the changes.

    animal 7-3. Entering lookup values

    The great thing about lookup tables is that you don't have to think of all the categories right now. Later, you can return to this table and add new categories as they pop upthe changes will automatically appear in the data entry list.

    7.1.2. Creating a Data List

    Now that you've laid the foundation, you can create the data entry list itself. To create the list, follow these steps:

    1. From the SharePoint site, choose Create Lists Custom List. SharePoint displays the New List page.

    2. Choose Modify settings and columns to add columns to the list. SharePoint displays the Customize page.

    3. In the Columns section, choose Add a new column. SharePoint displays Figure 7-4.

    4. Enter the information for the Date column, then repeat step 4 for each of the columns using the settings listed in Table 7-1.

    animal 7-4. Adding columns to the list

    Table 7-1. Data list column settings

    Name

    Column type

    Required?

    Default value

    Other settings

    Date

    Date/time

    No

    Today's date

     

    Type

    Lookup

    Yes

     

    Get information from : ExpenseTypes In this column: Title

    Price

    Currency

    Yes

     

     

    Taxable?

    Yes/no

    N/A

    Yes

     

    Total

    Calculated

    N/A

     

    Formula: [Price] + [Price] * [Taxable?] * .06 1

    a The sales tax rate in Florida is 6%. Change .06 to your own sales tax rate.


    When done, display the list and add a test entry to make sure it works as expected:

    1. Choose New Item. SharePoint displays the New Item page for the list. You should see fields for all of the columns except Total, which is read-only.

    2. Enter data and choose Save and Close. SharePoint returns you to the list and displays the new item. If the test entry was taxable, the correct Total should be displayed as shown in Figure 7-5.

    animal 7-5. Adding a test entry to make sure the list works

    7.1.3. Adding Totals, Groupings, and Filters

    As you enter items in the Expenses list, you may want to view the data in different ways. For example, you may want a running total of what you've spent or you may want to see what you spent on epoxy . Lists can include totals, and you can filter or group items in various ways. There are two ways to view totals in a list. Here is the easiest and most effective:

    1. Choose Edit in Datasheet.

    2. Choose the Totals button on the list toolbar. SharePoint displays totals for all of the numeric columns as shown in Figure 7-6.

    animal 7-6. Displaying totals in the Datasheet view

    The Datasheet view works only in Internet Explorer and only if Office 2003 Professional Edition is installed.


    The second way to view totals is to add Totals to the standard view. This approach isn't as useful as the Datasheet view because it doesn't total calculated columns. To add totals to the standard view.

    1. Choose Modify settings and columns.

    2. In the Views section, choose the view to modify. The default view is All Items. SharePoint displays the Edit View page.

    3. Expand the Totals section and select the type of total to display for each column as shown in Figure 7-7.

    4. Choose OK when done. SharePoint adds the column total to the top of the standard view.

    animal 7-7. Adding totals to a view

    If you don't see the choices shown in Figure 7-7, check the data type of the column: different data types support different choices.


    You can also modify the view to group items in interesting ways. For example, repeat the preceding procedure, but at step 3 expand the Group By section instead of Totals and make the changes shown in Figure 7-8.

    animal 7-8. Grouping items by type

    Now when you display the list, you'll see a categorized list of expenses. You can expand each expense type to see the details (Figure 7-9).

    animal 7-9. Viewing categorized expenses

    Use the Group By settings to create hierarchical views of lists. Use this view in a web part to create treeview-type controls. See http://usingsharepoint.com/Samples/TreeView.aspx for an example.


    Finally, you can filter the list to display only items that meet a certain criteria. The easiest way to do that is to choose the Filter button on the list toolbar and then apply a filter to one of the list columns. However, you can also add filters to a view using the Filter section of the Edit View page, as shown in Figure 7-10.

    animal 7-10. Adding a filter to a view

    Adding a filter to a view prevents members from viewing excluded itemsin this case, nontaxable expenses. That's not that useful in this context, but you can use it in other lists to hide unpublished or unapproved items.

    7.1.4. Modifying the New Item Form

    If you add items to the Expenses list through the standard New Item form, SharePoint returns you to the standard list view after you choose Save and Close. That's OK if you only want to add one item, but if you're adding a large set of records it gets annoying. To make lists truly useful for data entry, you need to change that behavior. There are a number of ways to do that, but the easiest way I found is to follow these general steps:

    1. Create a new, default view for the list.

    2. Open NewForm.aspx in FrontPage and copy the list form web part.

    3. Open the new view in FrontPage and paste the list form web part onto the view.

    4. Edit the new view in FrontPage as needed.

    Editing template pages such as NewForm.aspx or Default.aspx with FrontPage copies that page into the content database of the site. Afterward, changes to that page in the site template won't appear in the edited page. The page becomes unghosted.


    Putting the list form web part on a default list view ensures that SharePoint returns to that view when the member chooses Save and Close. Including a list view on the data entry form is actually pretty handy, since you can filter the view to show only the member's new entries. The following sections show you how to do this for the Expenses list.

    7.1.4.1 Creating a new default view

    To create a new default view for adding items to the Expenses list:

    1. Navigate to the Expenses list and choose Modify settings and columns.

    2. Scroll down to the Views section and choose Create a new view Standard View. SharePoint displays the Create View page.

Section

Option

Setting

Name

Make this the default view

Select

Audience

Create a public view

Select

Columns

Title (linked to item)

Select

 

Other columns

Clear

Sort

First sort column by the column:

Modified

Filter

Show items only when the following is true:

And

When column

Created by is equal to [Me]

Select

Created is equal to [Today]

Style

View Style:

Newsletter (no lines)

Item Limit

Number of items to display:

10

 

Limit the total number of items returned to the specified amount

Select


When you are finished, the new view will look similar to the All Items view, but it probably won't display any items, since the filter settings hide any items not created today by you. You won't see the data-entry form yet; but don't worry, that's next.

7.1.4.2 Add the list form web partlist form web part

To add the list form web part to the Add Items view:

  1. Open the site in FrontPage 2003.

  2. In the Folders view, select Lists Expenses to open the folder that contains the list.

  3. Open Add Items.aspx , find the WebPartPages:WebPartZone element and paste the copied section after it.

  4. Save Add Items.aspx , return to the browser and view the Expenses list to verify that the form appears on the view.

Figure 7-11 shows the paste operation when complete in FrontPage.

animal 7-11. Adding the list form web part to the view in FrontPage (after paste)

Here is the list form web part in its entirety:

 <WebPartPages:ListFormWebPart runat="server" WebPart="true" _   _WebPartId="{B8DFA085-E3C6-4296-BE00-CA527E3E07C9}" >     <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://schemas.microsoft.com/WebPart/v2">       <Title />       <FrameType>Default</FrameType>       <Description />       <IsIncluded>true</IsIncluded>       <PartOrder>1</PartOrder>       <FrameState>Normal</FrameState>       <Height />       <Width />       <AllowRemove>true</AllowRemove>       <AllowZoneChange>true</AllowZoneChange>       <AllowMinimize>true</AllowMinimize>       <IsVisible>true</IsVisible>       <DetailLink />     <HelpLink>http://wombat1/Using%20SharePoint%202003/_vti_bin/help/1033/sts/html/dlistwps.htm</HelpLink>       <Dir>Default</Dir>       <PartImageSmall />       <MissingAssembly />       <PartImageLarge />       <IsIncludedFilter />       <ExportControlledProperties>false</ExportControlledProperties>       <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>       <ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">  {5D70908D-7C12-4025-85FB-2110E8525ADE}  </ListName>       <FormType xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">8</FormType>       <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">0</ViewFlag>     </WebPart>     </WebPartPages:ListFormWebPart> 

The ListName element (shown in bold ) connects the web part to the list. You can use the same WebPartPages:ListFormWebPart element in any list if you change the ListName setting to match the list's globally unique identifier (GUID).

To find a list's GUID:

  1. Navigate to the list and choose Modify settings and columns.

  2. Copy the GUID from the Address bar in the browser (Figure 7-12).

animal 7-12. Finding a list's GUID

The GUID identifies the list inside the content database. SharePoint uses GUIDs to identify lists, web parts , and many other things.

7.1.4.3 Editing the new view

Some edits you make in FrontPage are compatible with SharePoint's page management features and some aren't. Adding a new web part through FrontPage is an edit that SharePoint can maintain. So, if you add new columns to the Expenses list, SharePoint adds fields for those columns to the Add Item page automatically.

That's a great feature, but it limits you to working through web parts. If you want to provide a different user -interface for data entry to a list, you need to create a new web part and install it on the server. Those are programming tasks I cover in Chapter 8, but those tasks are too complicated for most members.

A more simple solution is to customize the web part directly in FrontPage. Doing that makes the web part staticSharePoint no longer updates it when the list changesso make sure the design of your list is final before you do this. The following tutorial removes the standard list form toolbar and replaces it with command buttons to make data entry tasks a little more obvious.

To remove the toolbar:

  1. Open the site in FrontPage and create a copy of Add Items.aspx as a backup in case you break something.

  2. Open Add Items.aspx , right-click the list form web part, and choose List Form Properties from the Edit menu. FrontPage displays Figure 7-13.

  3. Clear the Show standard toolbar checkbox and choose OK. FrontPage removes the form toolbar from the web part.

  4. Choose File Save to save the change, and view the page in the browser to verify your changes.

animal 7-13. Removing the toolbar from the list form web part

To add command buttons:

  1. Right-click the list form web part, and choose Customize SharePoint List Form from the Edit menu. FrontPage switches the web part into edit mode.

  2. Click after the last tag on the web part and choose Insert Form Push button to insert a button on the web part as shown in Figure 7-14.

  3. Double-click the first button, label the button Clear Form , select the button type Reset, and choose OK.

  4. Double-click the second button, label the button Add Record , select the button type Normal, and choose OK.

  5. Edit the second buttons's HTML to include an onclick event:

     <input type="button" value="Add Record" name="B2"     onclick="javascript:ClickOnce(  );"> 

  6. Save the page and view the list in the browser to confirm that your changes worked.

animal 7-14. Adding a button to a web part

If you choose Revert SharePoint List Form from the web part's Edit menu, FrontPage removes the command buttons and restores the web part to its original state.


Finally, you'll also want to remove the toolbar from the data view web part that follows the data-entry form:

  1. Right-click the data view web part and choose Convert to XSLT Data View from the Edit menu. FrontPage displays the web part in Edit mode.

  2. Select the toolbar and delete it.

  3. Save the page and view the list in the browser to confirm that your changes worked.

When you are done, your data-entry form should look like Figure 7-15.

animal 7-15. Testing the completed data-entry form

There are a number of key points you should remember when editing web part pages in FrontPage:

  • Editing a page often means SharePoint no longer maintains it. Changes to the list or site won't automatically appear on the page.

  • Selecting Revert from a web part's Edit menu in FrontPage discards your edits and returns the web part to a default state.

  • Creating backup copies of files before you edit them is essential. Use the FrontPage Folders view to do so; then if the page stops working, you can delete the changed file and rename the backup copy to restore your prior version.

7.1.5. Changing Pages to View/Edit/Add Items

By building the data-entry form from a default list view in the preceding tutorial, I tricked SharePoint into redisplaying the form after adding each new record. I had set Add Items as the default view before any of the other steps, because once you modify the page in FrontPage, you can no longer change the view's properties from SharePoint. Try it:

  1. Navigate to the Expenses list and choose Modify settings and columns.

  2. In the Views section, choose the Add Items view. SharePoint displays a limited Edit View page. You can't add columns or change the view's settings.

If you set the default view to All Items or some other view, you can't switch the default view back to Add Items later. There's just no way to do that through SharePoint. Instead, use FrontPage to change the list's supporting file properties:

  1. In the FrontPage Folders view, open the Lists folder.

  2. Right-click on the Expenses list and choose Properties Supporting Files.


  3. The List Properties dialog in FrontPage lets you change the page used to perform the built-in list actions. You can also use it to restore the original list settings, such as changing the new item form back to NewForm.aspx .

    7.1.6. Saving the List as a Template

    Part of the beauty of SharePoint is that you can easily reuse your work. In the case of the Expenses list, this means that you can save the list as a template, then use that template to create new lists for categorizing expenses on other projects. Customized pages and links to other lists are preserved.

    To see how this works:

    1. Navigate to the list and choose Modify settings and columns Save site as template. SharePoint displays the Save as Template page.

    2. Choose Create Lists Expenses to create a test list based on the template.

    3. Table 7-3. List template settings

      Option

      Setting

      File name

      Expenses

      Template title

      Expenses

      Template description

      List for categorizing expenses on a project

      Include content

      Clear


      List templates are saved at the virtual-server level. That means the Expenses template is available to all sites on the virtual server; but since Expenses uses the ExpenseTypes lookup table, lists created from the template will only work correctly within the site that contains the ExpenseTypes list.

      I warned you about this in "Building a Lookup Table": lookup tables can't span web sites. If you want to be able to use the list template from other sites, select the column type Choice for the Types column. (See step 5 of the earlier section, "Creating a Data List.")




Essential SharePoint
Essential SharePoint 2007: A Practical Guide for Users, Administrators and Developers
ISBN: 0596514077
EAN: 2147483647
Year: 2005
Pages: 153
Authors: Jeff Webb

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net