SharePoint gets the value of the lookup field

Source: Internet
Author: User

It is common to get the value of the lookup field in a list, so we wrap it up

To get the lookup field value:

1         /// <summary>2         ///To get lookup field Id or Value3         /// </summary>4         /// <typeparam name= "T" ></typeparam>5         /// <param name= "item" ></param>6         /// <param name= "FieldName" ></param>7         /// <param name= "DefaultValue" ></param>8         /// <param name= "Getvaluetype" >0:return Id, 1:return Value</param>9         /// <returns></returns>Ten          Public StaticT getlookupfield<t> ( ThisSPListItem Item,stringFieldName,intGetvaluetype, T DefaultValue) One         { AFieldName = Fieldname.replace (" ", Constvariables.blankspicalcode); -  -             if(Item[fieldname] = =NULL) the             { -                 returnDefaultValue; -             } -  +             varitemelements = Regex.Split (Item[fieldname]. ToString (),";#", regexoptions.ignorecase); -  +             if(Itemelements.length >=2) A             { at                 returnConvertto<t>(Itemelements[getvaluetype], defaultvalue); -             } -             Else -             { -                 returnDefaultValue; -             } in}

Call this method: <oldplan is splistitem>
1. Get the ID of the lookup:

oldplan.getlookupfield<int> (Constvariables.Prcolumns. Columnstatus, 0, 0);

2. Get the value of lookup:

oldplan.getlookupfield<string> (Constvariables.Allbgprofilecolumns. Columnbgname, 1,string. Empty)

SharePoint gets the value of the lookup field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.