[英]Listview not shown in asp.net
I have tried to implement the listview in asp.net. 我试图在asp.net中实现listview。 But i can't get the output. 但是我无法获得输出。 where i make the mistake i don't know. 我在哪里弄错我不知道。 pls help me. 请帮助我。
My Model 我的模特
ASPX 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# 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 with Break point, i recognize the items list has the items. 在检查断点时,我知道项目列表中有项目。 but i cant get in my page. 但我无法进入页面。
Set the datasource for listview and try the below code 设置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();
}
I did not see any error. 我没有看到任何错误。 Could you please check your list added or not by writing them to console ? 您可以通过将其写入控制台来检查是否添加了您的列表吗?
Console.WriteLine();
foreach (Place item in items)
{
Console.WriteLine(item);
}
Please add an foreach function to see. 请添加一个foreach函数以查看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.