1

我有一個SharepointList如何將選擇字段保存到webpart中的Sharepoint列表中?

列表名稱:RegionList 領域:regId number Regname 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.

任何想法? Plz讓我知道如何將CheckBoxList項目存儲到CHOICE字段並對其進行修改。在此先感謝!

回答

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(); 
+0

感謝幾個小時後,我得到了來自博客同樣的事情... ! :) – 2013-03-19 08:48:41

相關問題