This document was originally published as Dynamics CRM 2011 Portal Development – CrmDataSource   and has been reproduced here to allow the community to correct any inaccuracies or provide other enhancements before updating the original version of this topic.

Dynamics CRM 2011 Portal Development  

CrmDataSource data source control connects to Dynamics CRM and retrieve EntityCollection 

IOrganizationService.RetrieveMultiple(QueryExpression)
IOrganizationService.RetrieveMultiple(QueryByAttribute)

and make it available for other controls to bind to, without requiring code. It supports Select, Create, Update and Delete data.

1. Select

It supports FetchXml and QueryByAttribute to retrieve EntityCollection.

I: FetchXml

FetchXml string can be specified inside <FetchXml></FetchXml> node and parameters can be specified by using <SelectParameters></SelectParameters> node. Parameters in FetchXml must be prefixed with “@” symbol. System.Text.RegularExpressions.Regex.Replace is used to replace the parameter names with a value provided.

Example:

<crm:CrmDataSource ID="CrmDataSource1" runat="server">
 <FetchXml>
 <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
 <entity name="adx_webpage">
 <attribute name="adx_webpageid" />
 <attribute name="aolor:#f8f8f8;"> <entity name="adx_webpage">
 <attribute name="adx_webpageid" />
 <attribute name/>
 <attribute name="createdon" />
 <order attribute="adx_name" descending="false" />
 <filter type="and">
 <condition attribute="adx_name" operator="eq" value="@name" />
 </filter>
 </entity>
 </fetch>
 </FetchXml>
 <SelectParameters>
 <asp:Parameter Name="name" DefaultValue="Cases" />
 </SelectParameters>
</crm:CrmDataSource>
 
<asp:GridView ID="GridView1" runat="server" DataSourceID="CrmDataSource1">
<Columns>
 <asp:BoundField DataField='adx_name' HeaderText="Name" />
 <asp:BoundField DataField='createdon' HeaderText="Created On" />
 </Columns>
 </asp:GridView>


Results:

 


II: QueryByAttribute

QueryByAttribute can be specified inside <QueryByAttribute></QueryByAttribute> node and parameters can be specified by using <SelectParameters></SelectParameters> node. Parameters specified in QueryByAttribute must be prefixed with “@” symbol.

EntityName, Attributes, Values, ColumnSet, Orders are implicit parameter names, which can be specified as parameter name in <SelectParameters></SelectParameters> node.

While <SelectParameters> can be used to provide values to any parameters defined in <QueryByAttribute></QueryByAttribute> node; <QueryParameters></QueryParameters> values are only added to QueryByAttribute.Attributes and QueryByAttribute.Values.

Example:

<crm:CrmDataSource ID=

"CrmDataSource1" runat="server">

 <QueryByAttribute EntityName="adx_webpage">
 <Attributes>
 <asp:ListItem Value="@queryAttr"></asp:ListItem>
 </Attributes>
 <ColumnSet>
 <asp:ListItem Value="adx_webpageid"></asp:ListItem>
 <asp:ListItem Value="adx_name"></asp:ListItem>
 <asp:ListItem Value="@timestamp"></asp:ListItem>
 </ColumnSet>
 <Orders>
 <asp:ListItem Text="desc" Value="adx_name"></asp:ListItem>
 </Orders>
 <Values>
 <asp:ListItem Value= </Orders>
"Home"></asp:ListItem>
 </Values>
 </QueryByAttribute>
 <SelectParameters>
 <asp:Parameter Name="timestamp" DefaultValue="createdon" />
 <asp:Parameter Name="queryAttr" DefaultValue="adx_name" />
 </SelectParameters>
 <QueryParameters>
 <asp:Parameter Name="adx_name" DefaultValue="Home" />
 </QueryParameters>
 </crm:CrmDataSource>
 
 <asp:GridView ID="GridView1" runat="server" DataSourceID="CrmDataSource1">
 <Columns>
 <asp:BoundField DataField='adx_name' HeaderText="Name" />
 <asp:BoundField DataField='createdon' HeaderText="Created On" />
 </Columns>
 </asp:GridView>

Result:
 



2. Update