Как отобразить поле ID как доступное только для чтения в форме редактирования списка точек доступа?

Мне нужно показать поле ID в форме редактирования списка sharepoint.

Есть способ сделать это? Я пробовал вычисляемое поле и ничего. Я знаю, что я могу видеть поле ID в представлении, и если я показываю как режим доступа. Я использую WSS3.0


person Guilherme de Jesus Santos    schedule 21.07.2010    source источник
comment
Вы создаете свой список через внешний интерфейс или функцию определения списка? Подходит ли вам настраиваемая форма редактирования?   -  person Shaneo    schedule 21.07.2010
comment
Создание его через интерфейс. Да, пользовательская форма редактирования является опцией.   -  person Guilherme de Jesus Santos    schedule 21.07.2010


Ответы (2)


Вы можете добавить поле ID в форму, используя JavaScript в CEWP.

<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, если вы предпочитаете легковесность.

person Ryan    schedule 26.07.2010
comment
Спасибо, Райан. Вот и все. Очень легко реализовать. - person Guilherme de Jesus Santos; 26.07.2010

Вы можете сделать это, создав пользовательскую форму редактирования довольно легко. Обычно я вставляю его в 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";
   }

}

person SPGuy    schedule 28.07.2010