Click here to Skip to main content
11,433,220 members (56,294 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 follow code the column only updates the first on in the list , how should i do tu update the others?
SPListItem item = list.GetItemById(1);
SPListItem item = list.GetItemById(2);
SPListItem item = list.GetItemById(3);

doing like this dont work , can somebody help me?
Posted 2-Dec-12 21:53pm
Kurac1859

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your code is incorrect because you can't define the same name for your types:
try this:
SPListItem item1 = list.GetItemById(1);
SPListItem item2 = list.GetItemById(2);
SPListItem item3 = list.GetItemById(3);
Or:
Or update each one by sending the id to a specific function:
public void updateMyRow(int id){
SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["MyList"];
            SPListItem item = list.GetItemById(id);
            
            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();
}

Call the function like this:

for(int id=1;id<4;id++){
updateMyRow(id);//update all rows
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.150428.2 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100