SP2010:如何创建过滤查找字段的列表视图

发布于 2024-09-27 10:29:44 字数 1726 浏览 2 评论 0原文

正如标题所示:在 sharepoint 2010 中,我需要以编程方式创建一个视图,让我可以过滤列表(人员列表)上的项目。在此人员列表中,我有一个引用另一个列表(项目)的查找字段:我需要仅显示在确定的项目上工作的人员(作为字符串传递)

我使用此代码创建了一个示例视图:

class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://dev_seventeen:999"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList books = web.Lists["Books"];
                    StringCollection fields = new StringCollection();
                    fields.Add("Title");
                    fields.Add("Publisher");
                    fields.Add("Autore");
                    var query = new XElement("Where",
                                    new XElement("Eq",
                                        new XElement("FieldRef", new XAttribute("Name", "Publisher")),
                                        new XElement("Value", new XAttribute("Type", "Choice"), "Alpha")
                                        )
                                    ).ToString(SaveOptions.DisableFormatting);

                    SPView view = books.Views.Add("TestView",
                        fields,
                        query,
                        100,
                        false,
                        false,
                        Microsoft.SharePoint.SPViewCollection.SPViewType.Html,
                        false
                        );
                    Console.WriteLine(query);
                    Console.ReadLine();
                }
            }
        }
    }

它过滤了在名为“Publisher”的选择类型字段上列出名为“Books”的列表,查找“Alpha”出版的所有书籍

我需要知道的是如何过滤查找字段而不是选择字段,因为如果我只是输入“Lookup” “而不是查询中的“选择”,它不起作用=(

谢谢

As the title says: in sharepoint 2010 i need to programmatically create a view which lets me filter on the items on a list (a list of person). In this person list i have a lookup field which refers to another list (projects): i need to show only the people that work on a determinated project (passed as a string)

I have created an example view using this code:

class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://dev_seventeen:999"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList books = web.Lists["Books"];
                    StringCollection fields = new StringCollection();
                    fields.Add("Title");
                    fields.Add("Publisher");
                    fields.Add("Autore");
                    var query = new XElement("Where",
                                    new XElement("Eq",
                                        new XElement("FieldRef", new XAttribute("Name", "Publisher")),
                                        new XElement("Value", new XAttribute("Type", "Choice"), "Alpha")
                                        )
                                    ).ToString(SaveOptions.DisableFormatting);

                    SPView view = books.Views.Add("TestView",
                        fields,
                        query,
                        100,
                        false,
                        false,
                        Microsoft.SharePoint.SPViewCollection.SPViewType.Html,
                        false
                        );
                    Console.WriteLine(query);
                    Console.ReadLine();
                }
            }
        }
    }

It filters a list named "Books" on a choice type field named "Publisher", looking for all books published by "Alpha"

What i need to know is how to filter on a lookup field instead of a chioce one, because if i just put "Lookup" instead of "Choice" in the query it doesn't work =(

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2024-10-04 10:29:44

您可以使用 LookupID 作为类型吗?这将确保您只有一场比赛。检查以下页面的查找字段、CAML 和LINQ:

Can you use LookupID as type? That would make sure you only have one match. Check the following pages for Lookup fields, CAML & LINQ:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文