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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with custom fields added to schema.xml 1

Status
Not open for further replies.

netsrac

Programmer
Jan 28, 2005
2
DE
Hi all!

I added a new field to the custom list (custlist) by adding the following entry to the schema.xml:

Code:
<Field Type="Integer" Name="State" DisplayName="State" Sealed="TRUE" Hidden="TRUE" ReadOnly="FALSE"/>

I set hidden=true because I need this field completly hidden to the UI. But when I try to set or get the value in this field I get an error (Object reference not set to an instance of an object).

Here is the part of my source code:

Code:
SPWeb myweb = SPControl.GetContextWeb(Context);
myweb.AllowUnsafeUpdates = true;
SPList list = myweb.Lists[[i]"List_name"[/i]];
list.Items[0]["State"] = 1; //an item with index 0 exits!!!
list.Items[0].Update();

output.Write(list.Items[0]["State"].ToString()); //this statement causes the error

If I try this code with the "title" field of the custom list or if I set hidden=false then it works. Does anybody know how to get this work?
 
I resolved the problem. With this code it works:

Code:
SPWeb myweb = SPControl.GetContextWeb(Context);
myweb.AllowUnsafeUpdates = true;
SPList list = myweb.Lists[[i]"List_name"[/i]];
SPListItem item = list.Items[0];
item.["State"] = 1;
item.Update();

output.Write(item["State"].ToString());
 
Hi,
I have simlar situation with yours.
I have add a field to schema.xml file.
I want to validate the input from user for this field. I saw you have code sample here. But I don't know where to put the code. It should be in aspx file or some other file.

Please give me advice.
Thanks a lot.
Ying
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top