开发者

Dropdown List using LinqDataSource Formatting Issue

开发者 https://www.devze.com 2023-02-21 13:30 出处:网络
I have a dropdownlist which is bound to one of the LDS. Here is the code for that: <asp:DropDownList ID=\"ddlEntities\" runat=\"server\"

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" 
开发者_如何学C    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?


You need to use the DataTextField and DataValueField properties on the dropdown list


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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号