首页 > 代码库 > SharePoint CMAL方式处理的 增,删,查,改
SharePoint CMAL方式处理的 增,删,查,改
SPContext.Current.Web.Lists["UserInfo"]:获取网站的List,名称是:UserInfo
userlist.AddItem():添加数据到List里
user.Update():将数据保存到List里,更新的List里的数据
GetItemById:获取当前行的ID
query.Query (XML的方式条件):过滤查询条件
增
protected void bt_SaveClick(object sender, EventArgs e) { SPList userlist = SPContext.Current.Web.Lists["UserInfo"]; SPListItem user = userlist.AddItem(); user["Title"] = this.tx_Title.Text; user["UserName"] = this.tx_UserName.Text; user["Gender"] = this.tx_Gender.Text; user["Tell"] = this.tx_tell.Text; user["Adress"] = this.tx_adress.Text; user.Update(); base.Response.Redirect("UserInfoList.aspx"); }
删
protected void bt_DeleteClick(object sender, EventArgs e) { using (Site9527EntitiesDataContext dataContext = new Site9527EntitiesDataContext(SPContext.Current.Web.Url)) { SPList userList = SPContext.Current.Web.Lists["UserInfo"]; SPListItem user = userList.GetItemById(Convert.ToInt32(tx_Del.Text)); user.Delete(); } tx_Del.Text = ""; bt_SelectClick(sender, e); }
查
public void bt_SelectClick(object sender, EventArgs e) { StringBuilder html = new StringBuilder(); SPList userList = SPContext.Current.Web.Lists["UserInfo"]; SPListItemCollection users = null; if (!string.IsNullOrEmpty(tb_UserName.Text)) { SPQuery query = new SPQuery(); query.Query = "<Where><Contains><FieldRef Name=‘UserName‘ /><Value Type=‘Text‘>" + tb_UserName.Text + "</Value></Contains></Where>"; users = userList.GetItems(query); } else { users = userList.Items; } foreach (SPListItem user in users) { html.Append("<tr>"); html.Append("<td>" + user.Title); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["UserName"])); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["Gender"])); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["Tell"])); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["Adress"])); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["ApprovalStatue"])); html.Append("</td>"); html.Append("<td>" + ConvertoString(user["ApprovalBy"])); html.Append("</td>"); html.Append("<td><a id=‘a_update‘ onclick=‘Update(" + user.ID.ToString() + ")‘>更新</a> <a id=‘a_delete‘ onclick=‘Delete(" + user.ID.ToString() + ")‘>删除</a>"); html.Append("</td>"); html.Append("</tr>"); }}
改
protected void bt_SaveClick(object sender, EventArgs e) { SPList userlist = SPContext.Current.Web.Lists["UserInfo"]; SPListItem user = userlist.GetItemById(Convert.ToInt32(Request.QueryString["ID"])); user["Title"] = this.tx_Title.Text; user["UserName"] = this.tx_UserName.Text; user["Gender"] = this.tx_Gender.Text; user["Tell"] = this.tx_tell.Text; user["Adress"] = this.tx_adress.Text; user.Update(); base.Response.Redirect("UserInfoList.aspx"); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。