Is it possible to display the FieldRenderingControl of a FormField without providing a ListId?
I'm creating a dynamic form based off of a content type. Most of the time the data from this form will be stored into a SharePoint list but the business requirements state that it needs to be able to save the data into an external database and bypass SharePoint completely.
I'm able to create the form by looping through all of the SPFields in the SPContentType object. However, in order to render the control, I need to provide a list ID. I can hack a solution by providing a dummy list ID but would like to make it as clean as possible.
Below is the code I'm using in a visual web part.
public partial class vwpDynamicFormCtrl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//Gets the CT data
string CTId = "0x010099999";
string listGUID = "99999999-9999-9999-9999-999999999999";
using (SPWeb web = SPContext.Current.Web)
{
SPList list = web.Lists[new Guid(listGUID)];
SPContentType oCT = web.AvailableContentTypes[new SPContentTypeId(CTId)];
//Loops through CT Fields and Generates a Form
foreach (SPField oSPF in oCT.Fields)
{
//Create TR
TableRow oTR = new TableRow();
TableCell oTCLabel = new TableCell();
TableCell oTCField = new TableCell();
//Populate TC Label
oTCLabel.Text = oSPF.Title;
////Populate TC Field
BaseFieldControl bfc = oSPF.FieldRenderingControl;
bfc.FieldName = oSPF.InternalName;
bfc.ControlMode = SPControlMode.Display;
bfc.ListId = list.ID; //<<< CAN I DO WITHOUT THIS???
oTCField.Controls.Add(bfc);
//Populate TR and Table
oTR.Cells.Add(oTCLabel);
oTR.Cells.Add(oTCField);
tblForm.Rows.Add(oTR);
}
}
}
}