Edit, delete, or insert records in a Data View

After you create a Data View that has as its data source a SharePoint list or library, an SQL database, or an XML file, you can easily add links for editing, deleting, or inserting records in the data source by using the browser.

For example, Northwind Traders, a gourmet food distribution company, tracks their inventory in an XML file. When inventory is low, a team member calls the supplier of that product and places an order. You suggest adding links for editing the Data View, so that the team member who places the order can immediately update the record for the item. You can also add insert and delete links to the Data View so that team members can add or remove products. That way, Northwind Traders will always have the most up-to-date information on their current inventory.

This article shows you how to add, edit, delete, and insert links to an existing Data View. To create the sample data and Data View that are used in the example, or to learn more about Data Views, see the article Create a Data View.

In this article


Before you begin

Microsoft Office SharePoint Designer 2007 has two separate features that make it possible for users to edit the data in a Data View through the browser:

  • Add links to an existing Data View     You can add links to an existing Data View so that users can edit, delete, or insert records in the data source. Users click the edit link for a record to put that item in edit mode. If you add links to a Data View that was inserted as a form, the links replace the form buttons. In addition, if you add links to a Data View that was inserted as a form, the Data View will no longer display form fields by default; by default it will only display data in a view.
  • Insert a Data View as a form     When you create a Data View, you can choose to insert it as a single-item or multiple-item form. The form is always in edit mode and it displays either one record or multiple records. Users can modify the existing records through the browser, but they cannot insert or delete records. You might want to choose a multiple-item form if users are likely to want to quickly edit the data in many records at the same time. For more information, see the article Insert a Data View as a form.

Data formats

This example uses an XML file as the data source. Because an XML file is a plain text file, it is not possible to specify the types of values that individual fields must contain. For example, there is nothing to prevent you from entering and saving text in a field that should contain numbers, such as UnitsOnOrder.

However, if your data source is a database or a SharePoint list or library, it is possible when you create the database, list, or library to specify the types of values that individual fields can contain. In such a case, if you use the form to enter text in a field that requires numbers, and then click Save, you receive an error message stating that the data source control failed to execute the update command. This happens because you are entering a value that the field in the data source cannot accept. If you receive such an error message, click the browser's Back button. Then either click Cancel on the form to discard your changes, or enter a value that the data source can accept.

When you design your form, you may want to include a note in each column header to indicate what form of data that field requires.

Top of Page Top of Page

Add links to edit, delete, or insert records in a Data View

These links can be added to any Data View, regardless of whether it was inserted as a view or a form. However, if you add these links to a Data View that was inserted as a form, the inserted links replace the form buttons. In addition, if you add links to a Data View that was inserted as a form, the Data View will no longer display form fields; it will only display data in a view. You cannot have a Data View that provides both the buttons and the links by using these features.

  1. Open the page that contains the Data View to which you want to add links.

To follow this example, use the Data View you created in Create a Data View.

Products.xml as it appears in a Data View

  1. Click the Data View, click the arrow Button image in the upper-right corner to show the Common Data View Tasks list, and then click Data View Properties. Click the arrow again to hide the list.

 Tip   Alternatively, you can right-click the Data View, and then click Show Common Control Tasks on the shortcut menu.

  1. In the Data View Properties dialog box, click the Editing tab.
  2. On the Editing tab, under Link Options, do one or more of the following:
    • To add a link for editing a record, select the Show edit item links check box.
    • To add a link for deleting a record, select the Show delete item links check box.
    • To add a link for inserting a new record, select the Show insert item link check box.

For this example, select the Show edit item links, Show delete item links, and Show insert item link check boxes.

Editing tab of Data View Properties dialog box

 Note   The preceding example is specific to XML files. When working with SQL databases, the Editing tab in the Data View Properties dialog box also provides an option to Auto-synchronize command options. When this option is selected, the update, delete, and insert commands from the SQL data source are synchronized with the edit, delete, and insert controls in the Data View.

  1. Click OK.

Each record in the Data View is now preceded by both an Edit link and a Delete link. In the lower-left corner of the Data View is an Insert link.

Multiple-item Data View with insert, edit, and delete links

  1. On the File menu, click Save As.
  2. In the Save As dialog box, in the File name box, type a name for your file, and then click Save.

Top of Page Top of Page

Edit, delete, or insert a record through the browser

After you save the page that contains the form, you can preview it in the browser and modify the data in the form.

Preview the Data View in the browser

  • In Office SharePoint Designer 2007, on the File menu, click Preview in Browser, and then click the browser type and size that you want to use.

Keyboard shortcut  Click the page that you want to preview in the Folder List, and then press F12.

The Data View that has the links appears in the browser.

Data View with links as it appears in the browser

Edit a record

  1. Click the Edit link for the record that you want to edit.

To follow the example, click the Edit link for Chai. A Data View that includes a data form for the Chai record appears.

Single record in a Data View in edit mode

 Notes 

  • When you are working with SharePoint lists and libraries, the edit controls are not text boxes but SharePoint form field controls.
  • When you are working with read-only fields, such as an ID in a SharePoint list or SQL database, the field is displayed only as text and not as an editable field.

You can now edit any of the information that appears in the Chai record.

  1. Edit the data for that record, and then either click Save to save your changes or click cancel to undo your changes and return to the Data View.

To follow the example, in the box in the UnitsOnOrder column, type 40, and then click Save to the left of the Chai record.

The Data View with the updated record appears.

Record with the UnitsOnOrder value

Delete a record

  • Click the Delete link to the left of the record that you want to delete.

 Important   When you delete a record through the browser, there is no prompt that asks if you are sure that you want to perform that action and there is no way to undo a deleted record.

To follow the example, click the Delete link to the left of Chang in the ProductName list. A Data View that has only four records appears.

Only 4 records appear in the Data View

Insert a record

  1. Click the Insert link in the lower-left corner of the Data View.

A record with empty form fields appears.

Record with empty form fields that appears when you click the insert link

You can now insert a new record.

  1. Enter the data for that record, and then either click save to save your changes or click cancel to undo your changes and return to the Data View.

To follow the example, in the box in the ProductName column, type Grandma's Boysenberry Spread. In the box in the UnitsInStock column, type 120. In the box in the UnitsOnOrder column, type 0. In the box in the ReorderLevel column, type 25. Click Save. A Data View with the new record appears.

New record that you inserted appears in the Data View

Top of Page Top of Page

Customize the Edit or Insert templates

Using a Data View to insert or edit records works a bit differently from, for example, using list forms such as NewForm.aspx or EditForm.aspx to add or edit items in a SharePoint list. A list or library displays a different page to users when they add or edit items, but a Data View displays a different mode. However, each mode has a template that you can fully customize. For example, if you customize the Edit template, users will see those customizations only when they click the edit link to put the Data View in edit mode.

You might want to customize each mode's template when, for example, you want to provide users with specific instructions when they insert or edit records. You can easily insert a new row below the column headers, and then use that row to enter text specifying what type of data should be entered in each column and what format that data should be in (text, numbers, etc.).

  1. Click the Data View, and then click the arrow Button image in the upper-right corner to show the Common Data View Tasks list.

 Tip   Alternatively, you can right-click the Data View, and then click Show Common Control Tasks on the shortcut menu.

  1. In the Data View Preview list, click Edit Template or Insert Template.

The template for that mode in the Data View appears. You can customize the look and feel of the template by changing the font, formatting, or layout of the form.

  1. To save your changes, on the File menu, click Save.
  2. To preview the template in the browser, on the File menu, click Preview in Browser, and then click the browser type and size that you want to use.

Keyboard shortcut  Click the page that you want to preview in the Folder List, and then press F12.

When you open the Data View in the browser, and then click Edit or Insert, the customized template that you created appears.

Top of Page Top of Page

 
 
Applies to:
SharePoint Designer 2007