1

我有一个 SharepointList

列表名称:RegionList 字段:(regId number Regname Choice复选框:允许多选)

Choice 字段项显示在 CheckBoxList 项中。我将这些项目保存为带有逗号分隔值的字符串。

protected string GetSelectedRegions()
        {
            List<String> regList = new List<string>();
            // Loop through each item.
            foreach (ListItem item in chkRegion.Items)
            {
                if (item.Selected)
                {
                    // If the item is selected, add the value to the list.
                    regList.Add(item.Value);
                }
                else
                {
                    // Item is not selected, do something else.
                }
            }

            String regs = String.Join(",", regList.ToArray());
            return regs;
        }

从上面的代码中,regs参数具有选定项目的数量并保存到列表中。现在,问题是当我打开列表并以Edit模式打开记录时CHOICE Field Doesn't Show any Selected ITEM. But, when i send only single value then it Show the Selected Item that was saved.

任何的想法? 请让我知道如何将 CheckBoxList 项目存储到 CHOICE 字段并检索它。提前致谢!

4

1 回答 1

1

对于设置多复选框,您应该像这样使用SPFieldMultiChoiceValue

protected SPFieldMultiChoiceValue GetSelectedRegions()
     {
        SPFieldMultiChoiceValue multiValue = new SPFieldMultiChoiceValue();

         List<String> regList = new List<string>();
        // Loop through each item.
        foreach (ListItem item in chkRegion.Items)
        {
            if (item.Selected)
            {
                // If the item is selected, add the value to the list.
                multiValue.Add(item.Value);
            }
            else
            {
                // Item is not selected, do something else.
            }
        }

        //String regs = String.Join(",", regList.ToArray());
        return multiValue;
    }

比设置你SPFieldMultiChoiceValue的 SPListItem

  item["multivalued choice field name"]= GetSelectedRegions();
于 2013-03-18T05:03:51.703 回答