Sharepoint 2010 如何将选择字段保存到Web部件中的Sharepoint列表?

Sharepoint 2010 如何将选择字段保存到Web部件中的Sharepoint列表?,sharepoint-2010,checkboxlist,multiple-choice,choicefield,Sharepoint 2010,Checkboxlist,Multiple Choice,Choicefield,我有一个共享点列表 列表名称:RegionList 字段:regId编号 Regname选项(复选框:允许多选) 选项字段项显示在复选框列表项中。 我正在将这些项保存为字符串,并使用逗号分隔的值 protected string GetSelectedRegions() { List<String> regList = new List<string>(); // Loop through each item

我有一个共享点列表

列表名称:
RegionList
字段:
regId编号
Regname选项
(复选框:允许多选)

选项字段项显示在复选框列表项中。 我正在将这些项保存为字符串,并使用逗号分隔的值

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;
        }
受保护的字符串GetSelectedRegions()
{
List regList=新列表();
//循环浏览每个项目。
foreach(chkRegion.Items中的ListItem项目)
{
如果(选定项)
{
//如果选择了该项,请将该值添加到列表中。
regList.Add(item.Value);
}
其他的
{
//未选择项目,请执行其他操作。
}
}
String regs=String.Join(“,”,regList.ToArray());
返回注册表;
}
从上面的代码中,
regs
参数包含所选项目的数量,并保存到列表中。 现在,问题是当我在
Edit
模式下打开列表并打开记录时,
CHOICE字段不会显示任何选中的项目。但是,当我只发送单个值时,它会显示已保存的选定项。

有什么想法吗?
请让我知道如何将复选框列表项存储到选择字段并检索。谢谢

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

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;
    }

对于“设置多个复选框”,您应使用如下方式:

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;
    }