c# - Listview not shown in asp.net -
i have tried implement listview in asp.net. can't output. make mistake don't know. pls me.
my model
aspx
<asp:listview id="listview1" runat="server"> <itemtemplate> <div> <asp:table runat="server" > <asp:tablerow> <asp:tablecell width="40%"> <asp:label id="label17" runat="server" font-bold="true" font-size="medium" text='<%#eval("roomtype") %>'></asp:label> </asp:tablecell> <asp:tablecell width="20%"> <asp:button id="button1" runat="server" text="search" /> </asp:tablecell> </asp:tablerow> <asp:tablerow> <asp:tablecell columnspan="2"> <asp:label id="label18" runat="server" font-bold="true" font-size="medium" text='<%#eval("description") %>'></asp:label> </asp:tablecell> </asp:tablerow> </asp:table> </div> </itemtemplate> </asp:listview>
c#
public class place { public string roomtype { get; set; } public string description { get; set; } } list<place> items = new list<place>(); items.add(new place() { roomtype = "roomtype1", description= "roomtype description"}); items.add(new place() { roomtype = "roomtype2", description = "roomtype description" }); items.add(new place() { roomtype = "roomtype3", description = "roomtype description" }); listview1.datasource = items;
while checking break point, recognize items list has items. cant in page.
set datasource listview , try below code
protected void page_load(object sender, eventargs e) { list<place> items = new list<place>(); items.add(new place() { roomtype = "roomtype1", description = "roomtype description" }); items.add(new place() { roomtype = "roomtype2", description = "roomtype description" }); items.add(new place() { roomtype = "roomtype3", description = "roomtype description" }); this.listview1.datasource = items; this.listview1.databind(); }
Comments
Post a Comment