The ListFieldIterator webcontrol

In some circumstances you’ll need to display a SPListItem in its display, edit or new mode in an application page for example. In that case you can iterate through each SPField of an SPList, find the appropriate webcontrol of the field’s datatype and set the appropriate rendering mode of the webcontrol.

The quickest / easiest way to do so is by using the BaseFieldControl class.This way it doesn’t matter which field you want to render. The right control will be used.

BaseFieldControl webControl = [SPField].FieldRenderingControl;
webControl.ListId = list.ID;
webControl.ItemId = item.ID;
webControl.FieldName = [SPField].Title;
webControl.ID = GetControlID([SPField]);
webControl.ControlMode = mode;


Another way to display a SPListItem in your custom webpart or application page is by using the ListFieldIterator Webcontrol. This webcontrol renders each SPField of a SPListItem with an appropriate webcontrol. That way you get the SharePoint look & feel and the validation of your form for free.



[ListFieldIterator_ListItem[9].jpg]



 



If you’d like to use the ListFieldIterator and would like to give the user the ability to display, edit or create a new SPListItem without having permissions on the SPList itself … you must set the SetContextWeb property of the ListFieldIterator with your elevated SPWeb object.



[ListFieldIterator_RunWithElevated[2].jpg]



 



  • Karine Bosch: ListFieldIterator Control


  • Using ListFieldIterator to display list’s New/Edit form in a new window


  • How to use the SharePoint Webcontrols


  • How SharePoint 2007 renders its content


  • Create Your Own Data Entry Form Web Part


  • ListFieldIterator Class
  • Comments

    Popular posts from this blog

    Setup SharePoint 2010

    Register CSS to SP Master Page