0

I have a web part in which I am showing the field values of the List Item. I want user to be able to edit the properties of the list item from web part only. To give the SharePoint like UI I want to use the FormField. My code is as below:

Webpart aspx code:

<table>
    <tr>
        <td id="tdTitle" runat="server">            
        </td>        
    </tr>
</table>

Code behind where I am creating the FormField.

private void SetFieldProperties(SPListItem communityItem)
{
    FormField fldTitle = new FormField();
    fldTitle.ItemId = communityItem.ID;
    fldTitle.ListId = communityItem.ParentList.ID;            
    fldTitle.FieldName = FieldNames.Title;
    fldTitle.InputFieldLabel = "Test";
    fldTitle.ControlMode = SPControlMode.Edit;
    fldTitle.Visible = true;
    fldTitle.ID = communityItem.ID + "_title";
    //fldTitle.ControlMode = Microsoft.SharePoint.WebControls.SPControlMode.Display;
    tdTitle.Controls.Add(fldTitle);
}

However, the code does not throw any error but the field is not getting rendered in the web part.

What am I missing?

4
  • The web part in which I am placing the form field is inside the sub web of the list where it resides. That is, the list is in parent web and the web part having form field is inside the sub web. Does it make any difference?
    – users1100
    May 9, 2015 at 12:13
  • Yes it does makes difference.. However if you have a Visual Web part why don't you use ASP.NET control and fill the dropdown etc. programmatically? May 9, 2015 at 15:01
  • Okay sir, I just thought to go with SharePoint own handling on the control if it is possible. But I should choose the suggested way to go with asp controls only.
    – users1100
    May 12, 2015 at 5:46
  • I will put it as an answer for you to accept to close the question. May 12, 2015 at 10:04

1 Answer 1

0

Yes it does makes difference.. However since you are using Visual Web part, you can use ASP.NET control and fill the dropdown etc. programmatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.