c# - Populate a ListView with Strings -


i'm bit new asp.net, bear me. came across this solution allow me add array of strings listview row of data. however, i'm not sure on proper way set up. in trying solution listview dropped onto website, i'm told new listviewitem() requires parameter of type listviewitemtype. sample solution doesn't provide that, different in asp.net?

so main question i'm asking is: if have array of strings, how can add listview row of data in asp.net?

edit: i'd make sure i'm asking right control. under impression listview like this (but in asp.net), i'm getting far not. it's line of text.

if want display in example, want use gridview instead of listview.

string collection not enough display in multiple columns. need collection of objects.

screen shot (top listview, bottom gridview)

enter image description here

sample code

<asp:listview runat="server" id="listview1">     <itemtemplate>         <%# eval("name") %>,          <%# eval("email") %>,          <%# eval("phone") %><br />     </itemtemplate> </asp:listview> <br/> <asp:gridview id="gridview1" autogeneratecolumns="true" runat="server" />  public class user {     public string name { get; set; }     public string email { get; set; }     public string phone { get; set; } }  protected void page_load(object sender, eventargs e) {     var collections = new list<user>         {             new user {name = "jon doe", email = "john@doe.com", phone = "123-123-1234"},             new user {name = "marry doe", email = "marry@doe.com", phone = "456-456-4567"},             new user {name = "eric newton", email = "eric@newton.com", phone = "789-789-7890"},         };      listview1.datasource = collections;     listview1.databind();      gridview1.datasource = collections;     gridview1.databind(); } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -