Export (0) Print
Expand All

SPDataSource.SelectCommand Property

Windows SharePoint Services 3

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

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

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.

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

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.

NoteNote

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>

Community Additions

ADD
Show:
© 2014 Microsoft