0

SPWeb web = SPContext.Current.Web;

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

            oListItem["Name"] = TextBox_Name.Text;
            oListItem.Update();

//my list wont get updated why?

3
  • 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
    Commented 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
    Commented 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
    Commented Nov 30, 2012 at 12:15

1 Answer 1

0

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;
        oListItem.Update();

        web.AllowUnsafeUpdates = false;

more info on AllowUnsafeUpdates:

http://hristopavlov.wordpress.com/2008/05/16/what-you-need-to-know-about-allowunsafeupdates/

full example

http://www.mssharepointtips.com/tip.asp?id=1176

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 and acknowledge you have read our privacy policy.

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