我尝试在asp.net 中实现listview。但我无法得到输出。我不知道我在哪里犯了错误。请帮助我。
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;
在检查断点时,我认识到项目列表中有项目。但我无法进入我的页面。
设置列表视图的数据源并尝试以下代码
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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)