2

我需要在共享点列表的编辑表单中显示 ID 字段。

有办法吗?我尝试了一个计算字段,但什么也没有。我知道我可以在视图中看到 ID 字段,以及是否显示为访问模式。我正在使用 WSS3.0

4

2 回答 2

3

您可以使用 CEWP 中的一些 JavaScript 将 ID 字段添加到表单中

<script type="text/javascript"
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">

$(function() {
  // Get the ID from the query string
  var id = getQueryString()["ID"];

  // Find the form's main table
  var table = $('table.ms-formtable');

  // Add a row with the ID in
  table.prepend("<tr><td class='ms-formlabel'><h3 class='ms-standardheader'>ID</h3></td>" +
                "<td class='ms-formbody'>" + id + "&nbsp;</td></tr>");
})

function getQueryString() {
  var assoc = new Array();
  var queryString = unescape(location.search.substring(1));
  var keyValues = queryString.split('&');
  for (var i in keyValues) {
    var key = keyValues[i].split('=');
    assoc[key[0]] = key[1];
    }
  return assoc;
}
</script>

如果您希望保持轻量级,还有一种不使用 jQuery 库的替代方法。

于 2010-07-26T12:00:31.613 回答
1

您可以通过非常轻松地创建自定义编辑表单来做到这一点。我通常将它粘贴到 webpart 中呈现的 HTML 表格中。可能有更好的方法来做到这一点,但它很简单而且很有效。

您要查看的关键行是 spFormField.ControlMode。这告诉 SharePoint 如何显示控件(无效、显示、编辑、新建)。因此,您要做的是检查您的 spField.InternalName == "ID" 是否存在,如果是,请将 ControlMode 设置为 Display。

其余的只是用于渲染列表的其余部分。

希望这可以帮助。

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";
   }

}

于 2010-07-28T22:33:33.737 回答