Friday, May 28, 2010

How to bind CRM Data to GridView on custom ASP.Net page for Microsoft Dynamics CRM

I have seen this article one of my colleague Hassan Hussain. I've decided to use other approach to bind data to GridView on custom ASP.Net page - instead BusinessEntitiesCollection I used Fetch.



string fetch = @"   <fetch mapping=""logical"">
<entity name=""account"">
<attribute name=""accountid""/>
<attribute name=""name""/>
<attribute name=""address1_line1""/>
<attribute name=""address1_line2""/>
<attribute name=""address1_country""/>
<attribute name=""address1_city""/>
</entity>
</fetch>";

string result = service.Fetch(fetch);

XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
doc.DocumentElement.Attributes.RemoveAll();

StringReader sr = new StringReader(doc.OuterXml);
DataSet ds = new DataSet();
ds.ReadXml(sr);

GridView1.DataSource = ds;
GridView1.DataBind();


And the result:

2 comments:

  1. Hi,

    Is there Fetch method in CRM 2011?

    string result = service.Fetch(fetch)

    ReplyDelete
    Replies
    1. Hello,
      There is no Fetch method in CRM 2011. But for back compatibility you can try to use ExecuteFetchRequest/ExecuteFetchResponse to get required data using FetchXml - http://technet.microsoft.com/en-us/library/microsoft.crm.sdk.messages.executefetchrequest.aspx

      Delete