I have a FormView that has a datasource bind as a object which is a WCF service. In the WCF Service i have a Object PublicationDetail which has a attribute List<string> authors;

I want to join the contents of the list and print them out in the form view however i fall on the following error:

Unable to cast object of type 'System.String[]' to type
'System.Collections.Generic.List`1[System.String]'.

And the code:

<asp:Label ID="AuthorsLabel" runat="server" Text='<%# String.Join( ",", ((List<string>)Eval("Authors")).ToArray()) %>' />
Member Avatar for LastMitch

@nered

How to display List contents in FormView

It would be nice if you can post a little more code than 1 line.

It's just the said line that is giving me the problem more so this part:

<%# String.Join( ",", ((List<string>)Eval("Authors")).ToArray()) %>

"Authors" is a List<string> type when i output it like everything else calling Bind("Authors") then i get the output of System.String[] so i need to transform the contents of the list which are strings to a joint string.

Member Avatar for LastMitch

@nered

so i need to transform the contents of the list which are strings to a joint string.

Unable to cast object of type 'System.String[]' to type System.Collections.Generic.List 1[System.String].

The reason why you have this error because you are trying to cast a Generic List<string> with a non generic list.

Is your generic list: List<Authors>?

You can try to used inherited class to the generic base List 1[System.String]

You can try to used Enumerable.ToArray() extension method instead ToArray() extension method.

No my list is List<string>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.