SPWeb web = SPContext.Current.Web;

            SPList oList = web.Lists["MyList"];
            SPListItem oListItem = oList.Items[1];

            oListItem["Name"] = TextBox_Name.Text;

//my list wont get updated why?

  • what's the problem you are facing? any error? or just it does not get updated, can you please debug your code and provide debug information/error log
    – Diptarag
    Nov 30, 2012 at 10:12
  • Maybe he don't change the name of list or nameof field. I think that is main problem here.
    – Grzegorz Z
    Nov 30, 2012 at 11:29
  • 1
    The code you provided should work fine unless u have incorrect list name or internal name of the field in your code.
    – Ishan
    Nov 30, 2012 at 12:15

1 Answer 1


I presume this is in a webpart if so try the following to see if it works :)

        SPWeb web = SPContext.Current.Web;

        web.AllowUnsafeUpdates = true;

        SPList list = Web.Lists["MyList"];

        SPListItem oListItem = List.Items[1];

        oListItem["Name"] = TextBox_Name.Text;

        web.AllowUnsafeUpdates = false;

more info on AllowUnsafeUpdates:


full example


also like others have noted that you need to check your list name is called "MyList" and its "Name" that you want to update ;)

hope it helps :)

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.