文本框列ByID [英] Textboxes column ByID
本文介绍了文本框列ByID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案
你的代码不正确,因为你不能为你的类型定义相同的名字:
试试这个:
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);
或者:
或者通过将id发送到特定函数来更新每一个:
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
这篇关于文本框列ByID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文