In this post we will discuss how we can hide a field in SharePoint list forms such a NewForm, EditForm or DispForm. Also you can check out my previous posts on:
Suppose you have a list that contains some fields and you want some fields should not appear in some forms.
This you can achieve by using SharePoint object model or also you can do this by using
SharePoint Manager Tool. This we will discuss in a separate post.
We can do this by using the SPField class.
using (SPSite site = new SPSite("http://sharepoint.crescent.com"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Employees"];
SPField field = list.Fields["Salary"];
field.ShowInNewForm = false;
field.ShowInEditForm = false;
field.ShowInDisplayForm = false;
field.Update();
}
}
Here after executing this code the Salary field of Employees list will not appear in any of the forms.