其他提示

您可以通过非常轻松地创建自定义编辑表单来执行此操作。我通常将其粘在WebPart中呈现的HTML表中。可能有更好的方法,但它很简单,它有效。

您要查看的键线是SpformField.ControlMode。这会告诉SharePoint如何显示控件(无效,显示,编辑,新)。所以你想要做的是检查你的spfield.internalname==“id”,如果它是,请设置要显示的控制器。

其余的只是绒毛,呈现列表的其余部分。

希望这有帮助。

HtmlTable hTable = new HtmlTable();
HtmlTableRow hRow = new HtmlTableRow();
HtmlTableCell hCellLabel = new HtmlTableCell();
HtmlTableCell hCellControl = new HtmlTableCell();
SPWeb spWeb = SPContext.Current.Web;

// Get the list we are going to work with
SPList spList = spWeb.Lists["MyList"];

// Loop through the fields
foreach (SPField spField in spList.Fields)
{
   // See if this field is not hidden or hide/show based on your own criteria
   if (!spField.Hidden && !spField.ReadOnlyField && spField.Type != SPFieldType.Attachments && spField.StaticName != "ContentType")
   {
     // Create the label field
     FieldLabel spLabelField = new FieldLabel();
     spLabelField.ControlMode = _view; 
     spLabelField.ListId = spList.ID;
     spLabelField.FieldName = spField.StaticName;

     // Create the form field
     FormField spFormField = new FormField();

// Begin: this is your solution here.
     if (spField.InteralName == "ID")
     { spFormField.ControlMode = SPControlMode.Display; }
     else
     { spFormField.ControlMode = _view; }
// End: the end of your solution.

     spFormField.ListId = spList.ID;
     spFormField.FieldName = spField.InternalName;

     // Add the table row
     hRow = new HtmlTableRow();
     hTable.Rows.Add(hRow);

     // Add the cells
     hCellLabel = new HtmlTableCell();
     hRow.Cells.Add(hCellLabel);
     hCellControl = new HtmlTableCell();
     hRow.Cells.Add(hCellControl);

     // Add the control to the table cells
     hCellLabel.Controls.Add(spLabelField);
     hCellControl.Controls.Add(spFormField);

     // Set the css class of the cell for the SharePoint styles
     hCellLabel.Attributes["class"] = "ms-formlabel";
     hCellControl.Attributes["class"] = "ms-formbody";
   }
.

}

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top