如何访问列表中的列表项 [英] How to access List Items in a list

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

问题描述

我正在尝试在 gridview 中显示 ListItems.

I'm trying to display the ListItems in a gridview.

请帮助我找到访问列表项的方法.

Please help me in finding a way to access the list items.

using (SPSite site = new SPSite("http://mysitehere......"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["TestList"];
        .......
        .......
    }
}

请帮助我访问列表项值.

Please help me in accessing the list item values.

推荐答案

下面的代码应该可以解决问题,获取完整的 来自 msdn 的文章

The below code should do the trick, get the full article from msdn here

using (SPSite site = new SPSite("http://mysitehere......"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["TestList"];
        SPListItemCollection collListItems = list.Items;
        foreach (SPListItem oListItem in collListItems)
        {
           string value = SPEncode.HtmlEncode(oListItem["Field1_Name"]);
           // do something with value
         }
    }
}

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

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