locked
Option Sets using CrmMetadataDataSource in ASP.NET RRS feed

  • Question

  • Hello,

    I must be missing something very simple!  I created the Xrm file and this works fine apart from Option Sets.

    I have the following web.config file:

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client" />
        <section name="microsoft.xrm.portal" type="Microsoft.Xrm.Portal.Configuration.PortalCrmSection, Microsoft.Xrm.Portal"/>
      </configSections>
      <connectionStrings>
        <add name="Xrm"
             connectionString="Server=http://server/crmorg; Domain=xxxxxx; Username=xxxxxxx; Password=xxxxxxxx"/>
      </connectionStrings>
      <microsoft.xrm.client>
        <contexts>
          <add name="Xrm" type="Xrm.XrmServiceContext, XRM" />
        </contexts>
      </microsoft.xrm.client>
      <microsoft.xrm.portal>
        <portals>
          <add name="Portal"/>
        </portals>
      </microsoft.xrm.portal>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <pages>
          <controls>
            <add tagPrefix="crm" namespace="Microsoft.Xrm.Portal.Web.UI.WebControls" assembly="Microsoft.Xrm.Portal" />
          </controls>
        </pages>
      </system.web>
    </configuration>

    I am then trying to access the default option set in the Case (incident) entity:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form1.aspx.cs" Inherits="TestPickList.Form1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:LinqDataSource ID="Contacts" ContextTypeName="Xrm.XrmServiceContext" TableName="ContactSet" runat="server" />
        <asp:GridView ID="GridView1" DataSourceID="Contacts" AutoGenerateColumns="false" runat="server">
            <Columns>
                <asp:TemplateField HeaderText="First Name">
                    <ItemTemplate>
                        <asp:Label ID="Label2" Text='<%# Eval("firstname")%>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Last Name">
                    <ItemTemplate>
                        <asp:Label ID="Label3" Text='<%# Eval("lastname")%>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="City">
                    <ItemTemplate>
                        <asp:Label ID="Label4" Text='<%#Eval("address1_city") %>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        </div>
        <div>
            <h2>Incident Picklists</h2>
            <h3>Priority</h3>
            <crm:CrmMetadataDataSource ID="PrioritySource" runat="server" 
                AttributeName="prioritycode" 
                EntityName="incident" />
            <asp:DropDownList ID="Priority" runat="server" 
                DataSourceID="PrioritySource" 
                DataTextField="OptionLabel" 
                DataValueField="OptionValue" />
        </div>
        </form>
    </body>
    </html>

    When i run this i get the gridview with contacts but the DropDownList is empty.  I have tried other Option sets but i get the same results.

    Thanks in advance

    Duane

    Wednesday, April 18, 2012 2:41 PM

Answers

  • Problem solved, the context was wrong <add name="Xrm" type="Xrm.XrmServiceContext, XRM" />
     it should have been
    <add name="Xrm" type="Xrm.XrmServiceContext, Test" />

    Test = assembly name.

    • Marked as answer by Duane Stead Wednesday, April 18, 2012 3:18 PM
    Wednesday, April 18, 2012 3:18 PM