Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
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 '12 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 '12 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 '12 at 12:15
add comment

1 Answer

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 :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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