Search code examples
c#linqlinq-to-sqllinqdatasource

Dropdown List using LinqDataSource Formatting Issue


I have a dropdownlist which is bound to one of the LDS. Here is the code for that:

<asp:DropDownList ID="ddlEntities" runat="server" 
    DataSourceID="LinqDataSource3">
</asp:DropDownList> 

And the code for LinqDataSource3 is:

 <asp:LinqDataSource ID="LinqDataSource3" runat="server" 
    ContextTypeName="Testing.DataAccess.TestingLinq2SqlVs1DataContext" 
    EntityTypeName="" Select="new (Name)" TableName="Entities" OrderBy="Name">
</asp:LinqDataSource>

Now I am getting the values in this type:

{Name = John}
{Name = Eric}

However, I want just:

John

to be showed. Where should I make changes?


Solution

  • I think you need to specify the DataTextField. Something like this:

    <asp:DropDownList ID="ddlEntities" runat="server"
       DataSourceID="LinqDataSource3" DataTextField="Name">
    </asp:DropDownList>