Listview没有显示在asp.net中 [英] Listview not shown in asp.net

查看:85
本文介绍了Listview没有显示在asp.net中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在asp.net中实现listview.但是我无法获得输出.我不知道在哪里犯错误.请帮助我.

I have tried to implement the listview in asp.net. But i can't get the output. where i make the mistake i don't know. pls help me.

我的模特

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;

在检查断点时,我识别出项目列表中有项目.但我无法进入我的页面.

While checking with Break point, i recognize the items list has the items. but i cant get in my page.

推荐答案

设置listview的数据源并尝试以下代码

Set the datasource for listview and try the below code

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

这篇关于Listview没有显示在asp.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆