0

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()) %>' />
2
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by nered
0

@nered

How to display List contents in FormView

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

0

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.

0

@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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.