码迷,mamicode.com
首页 > 其他好文 > 详细

SharePoint CMAL方式处理的 增,删,查,改

时间:2014-07-31 20:30:07      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   数据   for   cti   

 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");
        }

 

SharePoint CMAL方式处理的 增,删,查,改,布布扣,bubuko.com

SharePoint CMAL方式处理的 增,删,查,改

标签:style   blog   color   os   io   数据   for   cti   

原文地址:http://www.cnblogs.com/liuwj/p/3881269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!