【发布时间】:2013-08-21 23:59:50
【问题描述】:
在 EventReceiver 上,使用 c# 我想检索列表上 Sharepoint 2010 Choice 字段中的所有选定值。任何人都可以建议/提供有关如何从 Choice 字段中读取所有值的代码 sn-p 吗?
谢谢
【问题讨论】:
标签: c# visual-studio-2010 sharepoint-2010
在 EventReceiver 上,使用 c# 我想检索列表上 Sharepoint 2010 Choice 字段中的所有选定值。任何人都可以建议/提供有关如何从 Choice 字段中读取所有值的代码 sn-p 吗?
谢谢
【问题讨论】:
标签: c# visual-studio-2010 sharepoint-2010
请参阅此博文。这是这样做的正确方法。 http://www.c-sharpcorner.com/Blogs/10257/
SPFieldMultiChoiceValue choices = new SPFieldMultiChoiceValue(item["MultiChoice"].ToString());
for (int i = 0; i < choices.Count; i++)
{
Console.WriteLine(choices[i]);
}
【讨论】:
如果您有一个选择列,可以选择多个项目,您可以使用它来分隔它们:
string values = item["yourColumn"] as string;
string[] choices = null;
if (values != null)
{
choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
}
【讨论】:
我不确定你想做什么。如果您想从列表中获取字段(选择)中的所有值,我建议您将列表放入对象(SPList)中,遍历项目(yourSPListObject.items)
// get the current web you are in
SPWeb objWeb = SPContext.Current.Site.OpenWeb();
//get your list
SPList lstYourInfoList = objWeb.Lists["<ListNameHere"];
//Iterate through the items in the list
foreach(SPListItem item in lstYourInfoList.items){
//pick out your information needed
string choiceSelected = item["<ColumnNamethatrepresentsyourchoicefield>"].ToString();
//store your information somewhere
//store the string in a local list and pass this list back out
}
如果您想获得用户可以选择的所有选项,这可能会有所帮助
http://www.mindfiresolutions.com/SharePoint-Choice-Field--Fetch-Each-Choice-Item-80.php
希望这能回答你的问题
【讨论】: