共用方式為


SPView.Query property

取得或設定字串,包含檢視的查詢。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Property Query As String
    Get
    Set
'用途
Dim instance As SPView
Dim value As String

value = instance.Query

instance.Query = value
public string Query { get; set; }

Property value

Type: System.String
共同作業應用程式標記語言 (連同 CAML)字串,包含位置Groupby,或是 [排序方式的子句的查詢。

備註

設定Query屬性的查詢需要變更使用Update方法,在資料庫中才會生效。

Examples

下列程式碼範例會使用Query屬性,傳回的項目位置] 清單中指定的欄位會包含的值小於 1000年。

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("View_Name")

view.Query = "<Where><Leq><FieldRef Name='Field_Name'/>" _
             & "<Value Type='Number'>1000</Value></Leq></Where>"

view.Update()
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];

    oView.Query = "<Where><Leq><FieldRef Name=\"Field_Name\" />" +
    "<Value Type=\"Number\">1000</Value></Leq></Where>";

    oView.Update();
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

請參閱

參照

SPView class

SPView members

Microsoft.SharePoint namespace