2011-08-10 47 views

回答

1

我不確定你想做什麼。如果你想獲得的所有值從列表中的字段(選擇)我可以建議你到一個對象(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

希望如果你有一個選擇欄,其中多個項目,可以選擇這回答您的問與答

3

的選擇,你可以用它來分開它們:

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

重溫我的回答後,近三年來,我看到的做法有多髒了。你應該使用@Sia的答案,這是乾淨的方式來做到這一點。 – Hinek

6

看到這篇博文。這是做這件事的正確方法。 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]); 
} 
相關問題