2010-07-21 71 views
2

我需要在共享點列表的編輯表單中顯示ID字段。如何在編輯表單中將ID字段顯示爲只讀列表?

有辦法做到這一點嗎?我試了一個計算的字段,什麼也沒有。 我知道我可以看到視圖中的ID字段,並且如果我顯示爲訪問模式。 我正在使用WSS3.0

+0

是否經由前端或列表定義功能創建列表?自定義編輯表單是您的選擇嗎? – Shaneo 2010-07-21 15:09:07

+0

通過前端創建它。是的,自定義編輯表單是一個選項。 – 2010-07-21 17:44:10

回答

3

您可以add the ID field to the form using some JavaScript in a 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> 

如果您希望保持輕量化,還有一個替代方案method that doesn't use the jQuery library

+0

謝謝瑞安。而已。很容易實現。 – 2010-07-26 12:44:41

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

}

相關問題