如何显示列表视图列表项? [英] How to display List items in Listview?

查看:170
本文介绍了如何显示列表视图列表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的在我的aspx文件一个ListView:

I have a ListView in my aspx file like this:

<asp:ListView ID="ListView1" runat="server"></asp:ListView>

然后我有清单是这样的:

and then I have List like this:

List<string> mylist = new List<string>();

我试着去填充的ListView像这样:

Im trying to populate the ListView like so:

foreach(string elem in mylist)
{
  ListView1.Items.Add(new ListViewItem(elem));
}

但我的编译器告诉我最好的超载匹配误差放大器&;不能将字符串转换为ListViewItem的。这是一个asp.net 4.0 Web应用程序。有什么建议?

But my compiler is telling me best overload match error & cannot convert string to ListViewItem. This is a asp.net 4.0 web app. Any suggestions?

推荐答案

尝试结合您的ListView类似如下:

Try binding your ListView like the following:

code-背后

List<string> mylist = new List<string>() { "stealthy", "ninja", "panda"};
listView.DataSource = mylist;
listView.DataBind();

ASPX

<asp:ListView ID="listView" runat="server">
    <ItemTemplate>
        <asp:Label Text="<%#Container.DataItem %>" runat="server" />
    </ItemTemplate>
</asp:ListView>

这篇关于如何显示列表视图列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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