Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change field of a specific list item to be "required"?

Status
Not open for further replies.

123apple

Programmer
Aug 28, 2007
1
CA
Hello all,
I have a list with a dropdown field "status". I set another field f1 to be readonly and "not required" field. when adding a new list item, the initial "Status" is "proposed" and the Readonly field f1 won't show up in the "Edit form" page. So far so good.
I added 5 list items with status of "proposed". What I want is: when I edited #4 list item and changed the status to be "submitted", I would like the Readonly field f1 change to be "editable and required field" so it will show on the edit form as a required field.

*********************************************************
In the ItemUpdated Event:

public override void ItemUpdated(SPItemEventProperties properties)
{

try
{

using (SPWeb web = properties.OpenWeb())
{

SPList list = web.Lists[properties.ListId];
SPListItem item = properties.ListItem;
SPFieldCollection fields = item.Fields;
if (Convert.ToString(item["State"])!= "proposed")
{
SPField f1 = item.Fields["f1"];
f1.required = true;
f1.ReadOnlyField = false;
f1.Update();


}

}
********************************************************

The problem is : field f1 shows up on the Edit form for all the 5 items, not just #4 even though I retrieved the field f1 by properties.ListItem.Fields["f1"]. Does this mean fields can only be on List level, not list item level. what should I do if I want list item level fields ? thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top