文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SharePoint 2010 SPFieldLookup,SPFieldChoice更新值方法

SharePoint 2010 SPFieldLookup,SPFieldChoice更新值方法

时间:2010-11-05  来源:张大明

///////////////////////////////////

#region

 

//public method

 

///

<summary>

 

///

Returns the SPFieldLookupValue instance of a lookup value.

 

///

The ID value will be obtained using SPQuery.

 

///

</summary>

 

///

<param name="_web"></param>

 

///

<param name="_field"></param>

 

///

<param name="_lookupvalue"></param>

 

///

<returns></returns>

 

public SPFieldLookupValue GetLookupValue(SPWeb _web, SPFieldLookup _field, string

_lookupvalue)

{

 

string

queryFormat =

 

@"<Where>

<Eq><FieldRef Name='{0}'><Value Type='Text'>{1}</Eq>

</Where>"

 

;

 

string queryText = string

.Format(queryFormat, _field, _lookupvalue);

 

SPList lookupList = _web.Lists[new Guid

(_field.LookupList)];

 

SPListItemCollection

lookupItems =

lookupList.GetItems(

new SPQuery

if

(lookupItems.Count > 0)

{

 

int lookupId = Convert.ToInt32(lookupItems[0][SPBuiltInFieldId

.ID]);

 

return new SPFieldLookupValue

(lookupId, _lookupvalue);

}

 

else

{

 

return null

;

}

 

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

public void SetFieldValueLookup(SPListItem _item, string _fieldname, string

_lookupValue)

{

 

 

if (_item != null

)

{

 

 

SPFieldLookup field = _item.Fields.GetFieldByInternalName(_fieldname) as SPFieldLookup

;

_item[_fieldname] = GetLookupValue(_item.Web, field, _lookupValue);

_item.Update();

}

 

 

else

{

_item[_fieldname] =

 

null

;

}

}

 

 

///

<summary>

 

 

///

Set the values of a Lookup-Field with multiple values allowed.

 

 

///

</summary>

 

 

public void SetFieldValueLookup(SPListItem

_item,

 

 

string _fieldName, IEnumerable<string

> _lookupValues)

{

 

 

if (_item != null

)

{

 

 

SPFieldLookup

field =

_item.Fields.GetFieldByInternalName(_fieldName)

 

as SPFieldLookup

;

 

 

SPFieldLookupValueCollection

fieldValues =

 

 

new SPFieldLookupValueCollection

();

 

 

foreach (string lookupValue in

_lookupValues)

{

fieldValues.Add(

GetLookupValue(_item.Web, field, lookupValue));

}

_item[_fieldName] = fieldValues;

_item.Update();

}

}

 

 

public void SetFieldValueChoice(SPListItem _item, string _fieldname, string

_choiseValue)

{

 

SPFieldChoice statusField = _item.Fields.GetFieldByInternalName(_fieldname) as SPFieldChoice

;

_item[statusField.Id] = statusField.Choices[statusField.Choices.IndexOf(_choiseValue)];

_item.Update();

}

 

 

() { Query = queryText });

 

相关阅读 更多 +
排行榜 更多 +
西安交大通

西安交大通

生活实用 下载
长江云通

长江云通

生活实用 下载
translatez

translatez

生活实用 下载