Pergunta

I am using a Microsoft template for adding Training and Courses for people to register for. Everything is working fine, but I want to add a field to the Courses list. I want to add a field to indicate what type of staff this course is for, eg HR, Health & Safety, Admin, etc.

So I have searched all over for answers to this, the documentation on SharePoint is shocking, and I did the following:

  • Settings > Create Column on the Courses page.
  • Entered all necessary details
  • On DispForm, EditForm and NewForm (.aspx) added @fStaffType, Staff Type; to DataFields section. (Staff Type is the name of the field`)
  • On DispForm added a new row to display the data:

    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
           <H3 class="ms-standardheader">
               <nobr>Staff Type</nobr>
           </H3>
        </td>
       <td width="400px" valign="top" class="ms-formbody">
           <xsl:value-of select="@fStaffType"/>
        </td>
    </tr>
    
  • On EditForm and NewForm added a new row to edit/enter data:

    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
       <H3 class="ms-standardheader">
           <nobr>Staff Type</nobr>
       </H3>
        </td>
        <td width="400px" valign="top" class="ms-formbody">
            <SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="New" FieldName="fStaffType" __designer:bind="{ddwrt:DataBind('i',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@fStaffType')}"/>
            <SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="fStaffType" ControlMode="New"/>
        </td>
    </tr>
    

On EditForm and NewForm I get the error:

Error Rendering Control - ff12description_1

An unhandled exception has occured. Object reference not set to an instance of an object.

If I comment out the description it will show the first td (Field Name) but the second td is just empty.

Any help would be greatly appreciated!

EDIT: A related problem, don't know if I should create a new question or not. But Marc D Anderson answered below and I was able to add and display a new field. However, I can add a new Course perfectly but if I edit one, and change the Staff Type field, a new Course will be created at the current day and time. But if other fields are edited they edit correctly.

Any ideas?

Foi útil?

Solução

Many of the "Fabulous 40" templates have customized forms. (You'll probably debate the fabulous part of the name at this point.)

It looks like you are doing roughly the right things in the forms, but it's a little hard to tell where it's going south on you.

When you created the new column, did you give it a name of "fStaffType"? If not, that's the issue. If you named it "Staff Type", then the internal name (or StaticName) for the column is "Staff_x0020_Type". (The space in the name will be encoded.) EDIT: You can find the StaticName for a column by going into list settings and editing that column. The StaticName will be at the end of the URL as a Query String parameter. Depending on which characters you have used, it may bedouble encoded, like Staff%5Fx0020%5FType.

You don't need to add the column DisplayName and StaticName to the DiataFields section -- it doesn't really serve any obvious purpose, frankly. You'll just need to make sure that the column name in the SharePoint:FormField and SharePoint:FieldDescription matches the StaticName for the column name you've added.

The trailing "_1" in the error is part of the unique name that SharePoint gives each instance of that column in the page (you could be allowing edits to multiple items in the same form) by appending the value of the $Pos variable.

Outras dicas

Looks like ff12 is already defined somewhere else in the page and it's probably re-writing with _1 at the end.

  1. Can you just try drag and drop the field from the Data Source and let the designer figure out the field names?

OR

  1. Can you try adding the "Custom Edit Form" in another page and then copy the FieldDescription?

I may have not read or got good grasp of your needs. Why not implement Content Type? You could have feature for your custom fields (aka columns) and set attribute like diplay on edit form=true, show on view = true (etc.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top