SharePoint 목록의 편집 양식을 읽는 것으로 ID 필드를 표시하는 방법은 무엇입니까?
-
26-09-2020 - |
문제
SharePoint 목록의 편집 양식에 ID 필드를 표시해야합니다.
그것을 할 수있는 방법이 있습니까?나는 계산 된 필드와 아무것도 시도하지 않았습니다. 보기에서 ID 필드를 볼 수 있고 액세스 모드로 표시되는 경우 알아야합니다. WSS3.0
를 사용하고 있습니다해결책
에서 일부 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 라이브러리를 사용하지 않는 방법 가 가볍게 유지하는 것을 선호합니다.
다른 팁
사용자 지정 편집 양식을 쉽게 쉽게 만들어서이 작업을 수행 할 수 있습니다.나는 보통 웹 파트 내에 렌더링 된 HTML 테이블에 그것을 고수합니다.그 일을하는 더 좋은 방법이있을 수 있지만 간단하고 작동합니다.
보고 싶은 키 라인은 spformfield.controlmode입니다.이렇게하면 SharePoint가 컨트롤을 표시하는 방법 (잘못된, 디스플레이, 편집, 새로운)을 알려줍니다.따라서 할 일은 spfield.internalname=="ID"가 있는지 확인하는 것입니다. ControlMode를 표시 할 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