Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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?
C#
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

1 solution

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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900