Search code examples
sharepoint-2010

change value of yes/no field in sharepoint


I have a field of type Yes/No (checkbox) in my sharepoint list. I am trying to change/set the value of the field programmatically (server code), but it give me an error saying that it should be 1 or 0. I cannot get it working. Can anyone help me please?

here that part of the code:

 SPListItem item = reportList.Items.Add();
                item["RequesterID"] = id;

                 **item["ZIP_x0020_Code_x0020_Linked"] = 0;**

                item["ZC_x0020_code"] = txtZcCode.Text;
                item.Update();

Solution

  • For a Yes/No field, you should set it to "1" or "0":

    item["ZIP_x0020_Code_x0020_Linked"] = "0";
    

    Look here for more info:

    http://blog.henryong.com/2008/12/05/programmatically-setting-the-default-value-of-a-spfieldboolean-field/