ListViewByQuery class
Renders a list view within a Web Part or ASPX page according to a specified query.
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
Microsoft.SharePoint.WebControls.ListViewByQuery
Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
The following example defines the rendering of a Web Part in which the ListViewByQuery class is used to specify a query for cases where the Documents list contains "Sample" in the Subject column.
If the preceding example throws a NullReferenceException, verify that you have correctly used the List and Query properties. If you do not define the ViewFields property for the query, the example may raise an exception related to a missing list reference. If you do not create the SPQuery object with a view object, as seen in the example, the control will be rendered as a blank page.
The following example defines a query against a root Web site that returns the Title and Body column values for all items in the Announcements list where a field contains a specified user alias.
The previous example can be applied to an ASPX page by including a page directive that registers the Microsoft.SharePoint.WebControls namespace and inserting a control like the following within the form:
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> ... <SharePoint:ListViewByQuery ID="myListQuery" runat="server"/>