In sharepoint i have one list, list name FieldMapping.It contains 3 fields . For example in my list i given name like Sqlfields,contractfields and InputType. this field contains some values.In separate i was stored this field values like this

List<string> listOfsqlfields = new List<string>();
List<string> listOfLockfield = new List<string>();
foreach (SPListItem items in Inputtype)

    sqlfields = items["Title"].ToString();

   lockfields = items["InputType"].ToString();

   listOfLockfield.Add(lockfields );

I want to compare sqlfields and lockfields [![enter image description here][1]][1]

See this image here I want to compare SQLFields(here SQLFields are Contenttype fields) and InputType. If InputType is lock in form user not able to edit the column.

foreach (SPField field in oCType.Fields)

 FormField formField = new FormField();
 formField.ListId = olist.ID;
 formField.FieldName = field.InternalName;
 formField.ID = string.Format("Field_{0}",
 field.InternalName); // Unique Id to identify control on page 
  // formField.ControlMode = SPControlMode.Edit;

  //if (Lockfield == "Lock")

if (listOfsqlfields.Contains(formField.FieldName) != listOfLockfield.Contains(Lockfield))
formField.ControlMode = SPControlMode.Display;
  formField.ControlMode = SPControlMode.Edit;

For example in that image txtCan_ReqNum is lock while looping field.InternalName is txtCan_ReqNum then I want to execute this condition without hard coding the column name.

formField.ControlMode = SPControlMode.Display;

For example in that image PO_Num is UnLock while looping field.InternalName is PO_Num then I want to execute this condition.

formField.ControlMode = SPControlMode.Edit;

How can I achieve this? Thanks in Advance.


You can use a dictionary instead of list

Dictionary<string, string> mappings = new Dictionary<string, string>();
foreach (SPListItem items in Inputtype) {

Next inside the loop

foreach (SPField field in oCType.Fields){
   string lock = mappings[field.FieldName];

   //Use lock variable to use in the logic
| improve this answer | |
  • Thank you so much Amal. I tried like this It was working fine. – Elina Aug 3 '16 at 7:19
  • be careful with the .ToString() if you have no value in your field you have a NULL value, so you will got a NullReferenceException; You should use : Convert.ToString(items["FieldName"]) – Nico Aug 3 '16 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.