LINQ how to concatenate 2 db columns to display in dropdownlist
Posted
by
Simke Nys
on Stack Overflow
See other posts from Stack Overflow
or by Simke Nys
Published on 2012-11-13T10:54:07Z
Indexed on
2012/11/13
11:00 UTC
Read the original article
Hit count: 350
I'm trying to concatenate product_name
with product_prize_kg
by using LINQ so I can display it as one field in a dropdownlist. When I try to do this I get the following error.
value of type 'system.collections.generic.list(of anonymous type )' cannot be converted to ...
My code is like this:
Public Function selectAll() As List(Of tblProduct)
Dim result = From product In dc.tblProducts
Select New With
{
Key .productID = product.pk_product_id,
Key .productNameKg = Convert.ToString(product.product_name) & " " & Convert.ToString(product.product_price_kg)
}
Return result.ToList()
End Function
This is the dropdownlist that I want to fill.
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="productNameKg"
DataValueField="productID">
</asp:DropDownList>
Thanks
Grtz Simke
© Stack Overflow or respective owner