title: Replace SqlDataSource with EntityDataSource
body: <p>I have a DataGrid <em>(destination)</em> with a <em>countryID</em> column, this is binded to a DropDownList to view the countries. I have <em>countries</em> and <em>countryGroups</em> tables too, where <em>countries.countryGroupId = countryGroups.countryGroupId</em>. The list have to be formatted therefore I use SqlDataSource to get the formatted list:  </p>
  
  <pre><code>SELECT   c.countryID, cg.countryGroupName+': '+c.CountryName as Name
  FROM     countries AS c INNER JOIN
           countries_groups AS cg ON c.countryGroupID = cg.countryGroupID
  ORDER BY cg.Sort, c.CountryName
  </code></pre>
  
  <p>here's the dropdownlist originally binded to sqldatasource:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlCountryID" runat="server" Width="160px" DataSourceID="dsCountries"
       AppendDataBoundItems="true"  DataTextField="Name" DataValueField="countryID" 
       SelectedValue='&lt;%# Bind("countryID") %&gt;'&gt;
       &lt;asp:ListItem Value="" Text="Select"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>I would like to replace the SqlDataSource to EntityDataSource for the country field. I created the following <em>ProductionModel</em></p>
  
  <p><img src="https://i.stack.imgur.com/E3E6g.jpg" alt="ProductionModel.edmx"></p>
  
  <p>VS2010 has been created the public partial class <strong>ProductionEntities : ObjectContext</strong>...<br>
  I created an EntityDataSource:  </p>
  
  <pre><code>&lt;asp:EntityDataSource ID="EntityDataSource1" runat="server" 
      ConnectionString="name=ProductionEntities" 
      DefaultContainerName="ProductionEntities" EntitySetName="countries" 
      Include="" 
      onquerycreated="EntityDataSource1_QueryCreated" 
      ContextTypeName="ASPWebApp.Datasource.ProductionEntities"&gt;
  </code></pre>
  
  <p>My question is, <strong>what other steps are needed to finalyze the binding with EntityDataSource?</strong><br>
  Thanks in advance!</p>
  
  <p><strong>UPDATE:</strong>
  The solution became to be as follows (thanks to @Gaurav Jain)  </p>
  
  <pre><code>protected void ddlCountryID_OnInit(object sender, EventArgs e) {
    DropDownList ddlCountryID = sender as DropDownList;
    ddlCountryID.DataSource = (from c in db.suppliers_countries
                               join cg in db.suppliers_countries_groups on c.countryGroupID equals cg.countryGroupID
                               orderby cg.Sort, c.CountryName
                               select new {
                                      c.countryID,
                                      Name = cg.countryGroupName + ": " + c.CountryName
                               });
  }
  </code></pre>
  
  <p>and dropdownlist became to be:  </p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlCountryID" runat="server" Width="160px" AppendDataBoundItems="true"  
                    SelectedValue='&lt;%# Bind("countryID") %&gt;' **OnInit="ddlCountryID_OnInit"**  
                    DataTextField="Name" DataValueField="countryID"&gt;
                    &lt;asp:ListItem Value="" Text="Select"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>