簡體   English   中英

在 c# Visual Studio 2010 中檢索 Sharepoint 選擇字段的值

[英]Retrieve value of a Sharepoint Choice Field in c# Visual Studio 2010

在 EventReceiver 上,使用 c# 我想檢索列表上 Sharepoint 2010 選擇字段中的所有選定值。 任何人都可以建議/提供有關如何從選擇字段中讀取所有值的代碼片段嗎?

謝謝

請參閱此博客文章。 這是這樣做的正確方法。 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]);
}

如果您有一個選項列,其中可以選擇多個項目,您可以使用它來分隔它們:

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

我不確定你想做什么。 如果您想從列表中獲取字段(選擇)中的所有值,我建議您將列表放入對象(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
}

如果您想獲得用戶可以從 select 獲得的所有選擇,這可能會有所幫助

http://www.mindfiresolutions.com/SharePoint-Choice-Field--Fetch-Each-Choice-Item-80.php

希望這能回答你的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM