gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:31:24 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;

在检查断点时,我认识到项目列表中有项目。但我无法进入我的页面。

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