Whether the SharePoint Object Model Setting field is displayed on the new edit display page

Source: Internet
Author: User

If you use the PAGE method in SharePoint, whether it is the new field or the old field editing, it cannot set whether the field is creating NewForm. aspx, display DispForm. aspx, edit EditForm. the aspx page is displayed. The SharePoint object model allows you to easily implement this function. Each field includes ShowInDisplayForm, ShowInEditForm, and ShowInNewForm attributes. Use true and False to set whether to display the fields, the ShowInListSettings attribute is used to set whether the field is displayed on the "List Settings" page.

Now we will specify a field in the notification list in the new NewForm. aspx, display DispForm. aspx, edit EditForm. aspx and "list Settings" page display, C # code is as follows:

/// <Summary> /// set whether the field is displayed on the corresponding page. /// </summary> /// <param name = "web"> </param> /// <param name = "listName"> </param> protected void SetFieldShowPage (SPWeb web, string listName) {SPList list = web. lists [listName]; Microsoft. sharePoint. SPField field = list. fields. getField ("txtField"); // The field is not in DispForm. field is displayed on the aspx page. showInDisplayForm = false; // The field is in EditForm. field is displayed on the aspx page. showInEditForm = true; // The field is not in NewForm. field is displayed on the aspx page. showInNewForm = false; // The field is displayed on the list settings page. showInListSettings = true; // The field is displayed in the view. showInViewForms = true; field. update ();}

In the above Code, list is used. fields. getField ("txtField"); to obtain the Field object SPField with the specified name. When GetField is used to obtain the field, you can input an internal name or display name of the field.

After getting the SPField object, you can use the attribute settings to check whether the attributes are displayed on the corresponding page. The specific meaning of each attribute has been commented out in the Code, finally, you must use the Update () method of SPField to save the changes to the database.

Field. ShowInDisplayForm = false is used. The field cannot be displayed on the "view Projects" page, as shown in figure 1:

See: http://www.360sps.com/item/38eb9bbe217a46bea5d276525ab8b0e4.aspx for the original with diagram

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.