EditDetermining Visible fields
This describes a simple way to find the fields which should be displayed for new or edit mode by default.
EditThe Code
First off a simple function to determine if a field is hidden (we hide attachments as well, because the custom new/edit form web part deals with them specifically)
private static bool IsHidden(SPField field)
{
return (field.Hidden || field.ReadOnlyField || field.Type == SPFieldType.Attachments);
}
Second a loop through all the fields, determining which are visible for the Edit or New
modes - notice the odd logic, if ShowInNewForm/ShowInEditForm is null, then we just treat it as "true".
foreach (SPField field in list.Fields)
{
if (!IsHidden(field))
{
if (!field.ShowInNewForm.HasValue || field.ShowInNewForm.Value)
{
// do something
}
if (!field.ShowInEditForm.HasValue || field.ShowInEditForm.Value)
{
// do something
}
}
}
online essay services