7.1. Using Lists to Gather DataIf 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 listThe 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 controlsThere are a couple things you need to know about the column types:
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 TableBefore 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:
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:
| ||||||||||||||||||||||||||||||||||||||||||||||||||
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.
To add the list form web part to the Add Items view:
Open the site in FrontPage 2003.
In the Folders view, select Lists Expenses to open the folder that contains the list.
Open Add Items.aspx , find the WebPartPages:WebPartZone element and paste the copied section after it.
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.
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:
Navigate to the list and choose Modify settings and columns.
Copy the GUID from the Address bar in the browser (Figure 7-12).
The GUID identifies the list inside the content database. SharePoint uses GUIDs to identify lists, web parts , and many other things.
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:
Open the site in FrontPage and create a copy of Add Items.aspx as a backup in case you break something.
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.
Clear the Show standard toolbar checkbox and choose OK. FrontPage removes the form toolbar from the web part.
Choose File Save to save the change, and view the page in the browser to verify your changes.
To add command buttons:
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.
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.
Double-click the first button, label the button Clear Form , select the button type Reset, and choose OK.
Double-click the second button, label the button Add Record , select the button type Normal, and choose OK.
Edit the second buttons's HTML to include an onclick event:
<input type="button" value="Add Record" name="B2" onclick="javascript:ClickOnce( );">
Save the page and view the list in the browser to confirm that your changes worked.
|
Finally, you'll also want to remove the toolbar from the data view web part that follows the data-entry form:
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.
Select the toolbar and delete it.
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.
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.
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:
Navigate to the Expenses list and choose Modify settings and columns.
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:
In the FrontPage Folders view, open the Lists folder.
Right-click on the Expenses list and choose Properties Supporting Files.
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 .
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:
Navigate to the list and choose Modify settings and columns Save site as template. SharePoint displays the Save as Template page.
Choose Create Lists Expenses to create a test list based on the template.
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.
|