3 Replies - 1387 Views - Last Post: 15 January 2013 - 08:35 AM Rate Topic: -----

#1 neredsenvy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 13

How to display List<String> in FormView

Posted 12 January 2013 - 02:41 PM

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()) %>' />


How can i format this List<string> to a string. If i say
<%# Bind("Authors") or Eval("Authors") %>
, i get the following output: System.String[] everything else gives an compile error.

Should note im using Visual Studio 2012

Is This A Good Question/Topic? 0
  • +

Replies To: How to display List<String> in FormView

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3219
  • View blog
  • Posts: 10,799
  • Joined: 12-December 12

Re: How to display List<String> in FormView

Posted 12 January 2013 - 03:48 PM

Try it without ToArray().
Was This Post Helpful? 0
  • +
  • -

#3 neredsenvy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 13

Re: How to display List<String> in FormView

Posted 12 January 2013 - 04:14 PM

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

Was This Post Helpful? 0
  • +
  • -

#4 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: How to display List<String> in FormView

Posted 15 January 2013 - 08:35 AM

If removing ToArray doesn't change the error message, than the results must already be a string array. Instead of trying to cast to a list, try removing the cast and call the ToList function on the output.

<asp:Label ID="AuthorsLabel" runat="server" Text='<%# String.Join( ",", (Eval("Authors")).ToList()) %>' />



Disclaimer: I'm a C# dev, not VB, so I can't guarantee that VB has a ToList function.

EDIT: fixed tag

This post has been edited by h4nnib4l: 15 January 2013 - 08:39 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1