【问题标题】:Retrieve value of a Sharepoint Choice Field in c# Visual Studio 2010在 c# Visual Studio 2010 中检索 Sharepoint 选择字段的值
【发布时间】:2013-08-21 23:59:50
【问题描述】:

在 EventReceiver 上,使用 c# 我想检索列表上 Sharepoint 2010 Choice 字段中的所有选定值。任何人都可以建议/提供有关如何从 Choice 字段中读取所有值的代码 sn-p 吗?

谢谢

【问题讨论】:

标签: c# visual-studio-2010 sharepoint-2010


【解决方案1】:

请参阅此博文。这是这样做的正确方法。 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]);
}

【讨论】:

    【解决方案2】:

    如果您有一个选择列,可以选择多个项目,您可以使用它来分隔它们:

    string values = item["yourColumn"] as string;
    string[] choices = null;
    if (values != null)
    {
        choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
    }
    

    【讨论】:

    • 将近三年后重新审视我的答案,我看到这种方法有多肮脏。您应该使用@Sia 的答案,这是这样做的干净方法。
    【解决方案3】:

    我不确定你想做什么。如果您想从列表中获取字段(选择)中的所有值,我建议您将列表放入对象(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

    希望这能回答你的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多