c# - What is the best way to pull data into a web form's ListView? -
i'm new web forms, , build asp.net web application acts client connects wcf service via tcp connection pulls information , adds information listview object in web form. ideally, able store data in list , able sort, filter, add, remove, , delete items list messages come in, , update listview when these events occur.
what best way achieve type of behavior listview, , please show me coded example of how listview can bind list object contains rows of data listview, i'd list object contain 3 strings representing 3 different cells (one per column) in listview create following listview in browser:
column 1 header | column 2 header | column 3 header --------------------------------------------------- cell 1 text | cell 2 text | cell 3 text --------------------------------------------------- cell 4 text | cell 5 text | cell 6 text --------------------------------------------------- cell 7 text | cell 8 text | cell 9 text
here's basic idea.
have class represents data want display in listview:
public class somestuff { public string string1 { get; set; } public string string2 { get; set; } public string string3 { get; set; } }
then generate list of objects (from service, assume):
list<somestuff> allmydatastuffs = new list<somestuff>(); allmydatastuffs = mywcfservice.getmydata();
and bind list listview:
mylistview.datasource = allmydatastuffs; mylistview.databind();
you can display "string1", "string2", , "string3" in itemtemplate of listview.
<itemtemplate> <asp:label id="string1lbl" runat="server" text='<%# eval("string1")%>' /> <asp:label id="string2lbl" runat="server" text='<%# eval("string2")%>' /> <asp:label id="string3lbl" runat="server" text='<%# eval("string3")%>' /> </itemtemplate>
Comments
Post a Comment