Condividi tramite


SPDataSource.SelectCommand Property

Gets or sets a query that is used to retrieve list data.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Property SelectCommand As String
    Get
    Set
'Usage
Dim instance As SPDataSource
Dim value As String

value = instance.SelectCommand

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

Property Value

Type: System.String
A System.String object that contains a query expressed as a Collaborative Application Markup Language (CAML) fragment.

Remarks

The query string in the SelectCommand property is used by the associated SPDataSourceView object to select data.

Examples

The following example shows page markup that links a data-bound grid control to an SPDataSource control that is configured to query the Contacts list in the root Web site of a site collection. The SelectCommand property of the data source control contains a Where clause that filters list data to include only items where the job title contains the word "sales." The query also specifies that the data should be sorted on the Company field.

Note

The query string in the example has been modified to make it easier to read. On an actual ASP.NET page the string should be on a single line.

<SharePoint:SPDataSource ID="SPDataSource1" runat="server"
    DataSourceMode="List"
    UseInternalName="true" 
    SelectCommand="<Query>
                     <Where>
                        <Contains>
                          <FieldRef Name='JobTitle'/>
                          <Value Type='Text'>Sales</Value>
                        </Contains>
                     </Where>
                     <OrderBy>
                        <FieldRef Name='Company' Ascending='true' />
                     </OrderBy>
                   </Query>">
    <SelectParameters>
        <asp:Parameter Name="WebID" DefaultValue="RootWeb" />
        <asp:Parameter Name="ListName" DefaultValue="Contacts"  />
    </SelectParameters>
</SharePoint:SPDataSource>
     
<asp:GridView ID="GridView1" runat="server" EnableViewState="false"
    DataSourceID="SPDataSource1" 
    AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField HeaderText="Company" DataField="Company" />
        <asp:BoundField HeaderText="First Name" DataField="FirstName" />
        <asp:BoundField HeaderText="Last Name" DataField="Title" />
        <asp:BoundField HeaderText="Job Title" DataField="JobTitle" />
        <asp:BoundField HeaderText="Business Phone" DataField="WorkPhone" />
        <asp:BoundField HeaderText="Email Address" DataField="Email" />
    </Columns>
</asp:GridView>

See Also

Reference

SPDataSource Class

SPDataSource Members

Microsoft.SharePoint.WebControls Namespace

SelectParameters

SelectCommand