SharePointリストの編集フォームでIDフィールドを読み取る方法は?
-
26-09-2020 - |
質問
SharePointリストの編集形式でIDフィールドを表示する必要があります。
それをする方法がありますか?私は計算されたフィールドを試してみました。 私はビュー内のIDフィールドを見ることができ、そして私がアクセスモードとして表示されていることを知っています。 私はWSS3.0
を使っています解決
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 + " </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 Library を使用しない方法を軽量化したい場合は
他のヒント
カスタム編集フォームを簡単に作成することでこれを行うことができます。私は通常WebPart内でレンダリングされたHTMLテーブルにそれを貼り付けます。それをするより良い方法があるかもしれませんが、それは簡単でそれが機能します。
見たい鍵行はSpformField.ControlModeです。これにより、SharePointにコントロールを表示する方法(無効、表示、編集、新規)が表示されます。したがって、SPField.InternalName=="ID"の場合はチェックすることだけです。
を表示するようにControlModeを設定します。残りはリストの残りの部分をレンダリングするための毛羽立ちです。
これが役立つことを願っています。
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";
}
.
}
所属していません StackOverflow