locked
How to hide the "Content Type" field in the edit form. RRS feed

  • Question

  •  Hi all,

    I have a normal list with multiple content types.
    When you edit an item, the Content Type field is shown, and you can change the content type of the item.
    How to hide the "Content Type" field in the edit form ?

    I tried the following code:

    SPList CustomerList = Web.Lists["Customers"];  
    SPField ContentType =  
    CustomerList.Fields["Content Type"];  
    ContentType.ShowInEditForm = false;  
    ContentType.Update(true);
     

    and i tried in the ContentType FieldsIterator Class:
    if(field.Title == "Content Type" )  
          return true
    the "Content Type" field is always shown.

    Any idea or workaround?
    Thanks. 

    A.KHLIF
    Saturday, October 18, 2008 7:08 AM

Answers

  • I found it,
    If you are using a custom list definition, then simply remove this code from the template rendering definition :

    <SharePoint:ChangeContentType ID="ChangeContentType" runat="server"/> 

    And you will never see the Content Type drop-down in your Edit form.
    A.KHLIF
    • Marked as answer by A.KHLIF Monday, October 20, 2008 7:39 AM
    Monday, October 20, 2008 7:39 AM

All replies

  • The Content Type drop-down is an out of the box menu that will alway display if you have more than one Content Type available. As a result, I don't think you can hide it using normal methods.

    If you _really_ want to hide the menu (so that it is impossible to change the content type after an item has been creted) then I suggest you customise the edit form and embed some JavaScript to hide the control.

    If you are creating a List Definition, then you can use a similar approach with a custom Edit Form.
    regards
    Martin Hatch
    MCPD .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog
    Saturday, October 18, 2008 3:29 PM
  • I found it,
    If you are using a custom list definition, then simply remove this code from the template rendering definition :

    <SharePoint:ChangeContentType ID="ChangeContentType" runat="server"/> 

    And you will never see the Content Type drop-down in your Edit form.
    A.KHLIF
    • Marked as answer by A.KHLIF Monday, October 20, 2008 7:39 AM
    Monday, October 20, 2008 7:39 AM
  • how do you use this piece of code?  Where to insert it in SPD?

    thanks!
    Tuesday, February 3, 2009 7:46 PM
  • You don't modify it from SPD, you need to be developing your own List Definitions or Content Types.

    Then you work with XML definition files that control the rendering templates.
    regards
    Martin Hatch
    MCPD .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog
    Wednesday, February 4, 2009 10:27 AM
  • Have you tried setting Allow Management of Content Types property to No under the list settings? 
    Thursday, December 16, 2010 7:37 PM
  • I remember I ran into this issue... just go to Settings->List Setting->Advanced Setting & choose Allow Management of content Type to "NO"

     

    As suggested by Kevin

    Thursday, March 31, 2011 9:11 PM