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 list = web.Lists["MyList"];
SPListItem item = list.GetItemById(1);

item["Title"] = TextBox_Name.Text;
item["ProductNumber"] = TextBox_ProdNum.Text;
item["ListPrice"] = TextBox_ListPrice.Text;
item["Color"] = TextBox_Color.Text;
item["More Info"] = TextBox_MoreInfo.Text;

item.SystemUpdate(false);
list.Update();

after writing following code in the list its only replace the first product not if i take more products in the list its only updates the one on place 1... can somebody help me ?

share|improve this question
add comment

1 Answer

GetItemById takes the Item whose Id is given in the function! so if you hardcode it to 1, it will always take the first List Item!

You should learn basics of SharePoint Object Model, if you want all the Items in the List simply use SPList.Items property to get all the items in the List

You can use SPQuery to get your desired items and use List.GetItems!

Once you run a query you will get SPListItemCollection and you can use foreach with collection to update bulk items!

So it depends upon what you are trying to achieve, get hold of SP Object Model!

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.