2

SharePointリストの編集フォームに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

これを行うには、カスタム編集フォームを非常に簡単に作成します。私は通常、Webパーツ内にレンダリングされた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 に答える