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