Click here to Skip to main content
13,003,516 members (58,863 online)
Rate this:
 
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 20:53pm
Kurac1866

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2017
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