Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net中未显示Listview_C#_Asp.net_Listview - Fatal编程技术网

C# asp.net中未显示Listview

C# asp.net中未显示Listview,c#,asp.net,listview,C#,Asp.net,Listview,我尝试在asp.net中实现listview。但是我不能得到输出。我不知道我在哪里犯了错。请帮帮我 我的型号 ASPX <asp:ListView ID="ListView1" runat="server"> <ItemTemplate> <div> <asp:Table runat="server" > <a

我尝试在asp.net中实现listview。但是我不能得到输出。我不知道我在哪里犯了错。请帮帮我

我的型号

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#

公共课堂场所
{
公共字符串RoomType{get;set;}
公共字符串说明{get;set;}
}
列表项=新列表();
添加(newplace(){RoomType=“RoomType1”,Description=“RoomType Description”});
添加(newplace(){RoomType=“RoomType2”,Description=“RoomType Description”});
添加(newplace(){RoomType=“RoomType3”,Description=“RoomType Description”});
ListView1.DataSource=项目;
在使用Break point进行检查时,我发现项目列表中有这些项目。但是我无法进入我的页面


我没有看到任何错误。您可以通过将列表写入控制台来检查是否添加了列表吗

Console.WriteLine();
        foreach (Place item in items)
        {
            Console.WriteLine(item);
        }

请添加foreach函数以查看。

为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();
        }
受保护的无效页面加载(对象发送方,事件参数e)
{
列表项=新列表();
添加(newplace(){RoomType=“RoomType1”,Description=“RoomType Description”});
添加(newplace(){RoomType=“RoomType2”,Description=“RoomType Description”});
添加(newplace(){RoomType=“RoomType3”,Description=“RoomType Description”});
this.ListView1.DataSource=项目;
this.ListView1.DataBind();
}

在哪里设置listview的数据源?需要ListView1.DataBind();好的,瑜伽士,我现在解决了谢谢你,先生,这个.ListView1.DataBind();我想念this@Sagotharan酷,如果我试图标记,请将此标记为答案,但我刚刚更新了我的qus,所以网站不允许立即标记。下一步,我想筛选我的listview,。我是否需要删除C#中的列表项,或其中的任何隐藏选项?您的意思是使用类似寻呼机的控件来对列表进行分页,还是需要筛选绑定到列表视图的数据?谢谢,先生,我尝试了这个方法,但我无法纠正错误并输出。@Sagotharan所以您没有列表视图的数据源,先生。我没有注意到这一点
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();
        }