SP2010:如何创建过滤查找字段的列表视图
正如标题所示:在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
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:over Lookup fields
by Value