gpt4 book ai didi

c# - ListView 未显示在 asp.net 中

转载 作者:行者123 更新时间:2023-12-02 04:34:44 24 4
gpt4 key购买 nike

我试图在 asp.net 中实现 ListView 。但我无法得到输出。我在哪里犯了我不知道的错误。请帮助我。

我的模型

enter image description here

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;

在检查 Break point 时,我发现项目列表中有项目。但我无法进入我的页面。

enter image description here

最佳答案

为 ListView 设置数据源并尝试下面的代码

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();
}

关于c# - ListView 未显示在 asp.net 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22217782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com