Binding a referenced member to RadGrid while using EntityDataSource control

4 posts, 0 answers
  1. Sundarar Ramasamy
    Sundarar Ramasamy avatar
    1 posts
    Member since:
    Oct 2006

    Posted 17 Feb 2010 Link to this post


    I got stuck in an issue while trying to bind a reference member (navigation property - foreign key reference) to a dropdownlist. I have Telerik RadGrid control which gets the data using a EntityDataSource control. Here is the model description:

    Applications: AppId, AppName, ServerId 
    Servers: ServerId, ServerName 

    The Applicaitons.ServerId is a foreign key reference to Servers.ServerId. The RadGrid lists the applications and allows the user to insert/update/delete an application. I want to show the server names as a dropdownlist in edit mode which I'm not able to. . Here is my aspx code:

    <telerik:RadGrid ID="gridApplications" runat="server" Skin="Sunset"  
        AllowAutomaticInserts="True" AllowAutomaticDeletes="True" 
        AllowPaging="True" AllowAutomaticUpdates="True"  
        AutoGenerateColumns="False" OnItemCreated="gridApplications_ItemCreated"  
        DataSourceID="applicationsEntityDataSource" Width="50%"  
        OnItemDeleted="gridApplications_ItemDeleted" GridLines="None"
        <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" DataKeyNames="AppId" DataSourceID="applicationsEntityDataSource"
                <HeaderStyle Width="20px" /> 
                <HeaderStyle Width="20px" /> 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit" ItemStyle-Width="10%"
                <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete this application?" ConfirmTitle="Confirm Delete" ConfirmDialogType="Classic" ItemStyle-Width="10%" HeaderText="Delete"
                <telerik:GridBoundColumn DataField="AppId" UniqueName="AppId" Visible="false" HeaderText="Application Id" ReadOnly="true"
                <telerik:GridBoundColumn DataField="AppName" UniqueName="AppName" HeaderText="Application Name" MaxLength="30" ItemStyle-Width="40%"
                <telerik:GridTemplateColumn DataField="ServerId" UniqueName="ServerId" HeaderText="Server Hosted" EditFormColumnIndex="1"
                        <asp:DropDownList ID="ddlServerHosted" runat="server" DataTextField="Servers.ServerName" DataValueField="ServerId" Width="40%"
            <EditFormSettings ColumnNumber="2" CaptionDataField="AppId" InsertCaption="Insert New Application" EditFormType="AutoGenerated"
                <EditColumn InsertText="Insert record" EditText="Edit application id #:" EditFormColumnIndex="0" UpdateText="Application updated" UniqueName="InsertCommandColumn1" CancelText="Cancel insert" ButtonType="ImageButton"></EditColumn> 
                <FormTableItemStyle Wrap="false" /> 
                <FormTableStyle GridLines="Horizontal" CellPadding="2" CellSpacing="0" Height="110px" Width="110px" /> 
                <FormTableAlternatingItemStyle Wrap="false" /> 
                <FormStyle Width="100%" BackColor="#EEF2EA" /> 
                <FormTableButtonRowStyle HorizontalAlign="Right" /> 
    <asp:EntityDataSource ID="applicationsEntityDataSource" runat="server"  
        ConnectionString="name=AnalyticsEntities" EnableDelete="True"  
        EntityTypeFilter="Applications" EnableInsert="True" EnableUpdate="True" EntitySetName="Applications"  
        DefaultContainerName="AnalyticsEntities" Include="Servers"

    I tried another approach where I replaced the GridTemplateColumn with the following code

    <telerik:RadComboBox ID="RadComboBox1" DataSourceID="serversEntityDataSource" DataTextField="ServerName" DataValueField="ServerId" AppendDataBoundItems="true" runat="server" > 
        <telerik:RadComboBoxItem /> 

    and using a separate EntityDataSource control as follows:

     <asp:EntityDataSource ID="serversEntityDataSource" runat="server"  
        ConnectionString="name=AnalyticsEntities" EnableDelete="True"  
        EntityTypeFilter="Servers" EnableInsert="True" EnableUpdate="True" EntitySetName="Servers"  
    I'm able to populate the dropdownlistbox, but I get the following error, when I try to insert a new record.
    Application cannot be inserted. Reason: Entities in 'AnalyticsEntities.Applications' participate in the 'FK_Servers_Applications' relationship. 0 related 'Servers' were found. 1 'Servers' is expected.  
    My question is, how do you bind the navigation property and load the values in the DropDownList/RadComboBox control? Do I need two separate EntityDataSource control or just one control is enough?

    I use the Telerik RadControls for ASP.NET AJAX Q3 2009 SP2. The environment is as follows:
    Windows XP SP3, Visual Studio 2008/.NET Framework 3.5, Visual C#.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Feb 2010 Link to this post

    Please have a look at the forum link below where I have provided a similar solution on how to populate the dropdownlist in the template column based on a foreign key value. You can use a similar approach and use the label  as the control parameter  for the data source control in the EditItemTemplate.
    Hope this helps.
  3. DevCraft R3 2016 release webinar banner
  4. Saxon
    Saxon avatar
    7 posts
    Member since:
    Nov 2015

    Posted 22 Apr in reply to Princy Link to this post

    dead link reference
  5. Marin Bratanov
    Marin Bratanov avatar
    3555 posts

    Posted 26 Apr Link to this post

    Hello Saxon,

    I have found the post from Princy in an old database and I am pasting it below. Note that it had been in the old ASP.NET "Classic" forums and that suite is discontinued. As such, the post is very old so I removed the original link as it cannot be restored.


    I have placed the SqlDataSource in the ItemTemplate along with the Dropdownlist and used an invisible label to pass the key value as the parameter. Please try this and let me know how it goes.


                          <asp:Label ID="Label1" Visible="false" runat="server" Text='<%#Eval("EmployeeID") %>'></asp:Label>
                          <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                              runat="server" SelectCommand="SELECT TerritoryID FROM EmployeeTerritories  where EmployeeID = @EmployeeID">
                                  <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="EmployeeID" />
                          <asp:DropDownList ID="DropDownList1" DataTextField="TerritoryID" DataValueField="TerritoryID"
                              DataSourceID="SqlDataSource2" runat="server">



    Marin Bratanov
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top