zoukankan      html  css  js  c++  java
  • sharepoint Linq方式的增,删,查,改

    Site9527EntitiesDataContext (重要的类):连接实体与网站List操作
    SPContext.Current.Web.Url:获取当前操作的页面
    FirstOrDefault:使用时一定要先引用(Using System.Linq;)
    dataContext.SubmitChanges():确保数据更新到List中。


      protected void bt_SaveClic(object sender, EventArgs e)
           {
               using (Site9527EntitiesDataContext dataContext = new Site9527EntitiesDataContext(SPContext.Current.Web.Url))
               {
                   UserInfoItem user = new UserInfoItem();
                   user.Title = this.tx_Title.Text;
                   user .UserName = this .tx_UserName.Text;
                   user.Gender = this.tx_Gender.Text;
                   user.Adress =this. tx_adress.Text;
                   dataContext.UserInfo.InsertOnSumbit(user);
                   dataContext.SubmitChangers();
               }
               base.Response.Redirect("UserInfoList.aspx");
           }

      protected void bt_DeleteClick(object sender, EventArgs e)
            {
                using (Site9527EntitiesDataContext dataContext = new Site9527EntitiesDataContext(SPContext.Current.Web.Url))
                {
                    UserInfoItem user = null;
                    user = dataContext.UserInfo.FirstOrDefault(i => i.Id ==Convert.ToInt32(tx_Del.Text));
                    dataContext.UserInfo.DeleteOnSubmit(user);
                    dataContext.SubmitChanges();
                }
                tx_Del.Text = "";
                bt_SelectClick(sender, e);
            }

      public void bt_SelectClick(object sender, EventArgs e)
            {
                StringBuilder html = new StringBuilder();
                IQueryable<UserInfoItem> userList=null;
                if (!string.IsNullOrEmpty(tb_UserName.Text))
                {
                     using(Site9527EntitiesDataContext dataContext=new Site9527EntitiesDataContext(SPContext.Current.Web.Url))
                    {
                        userList = dataContext.UserInfo.Where(i => i.UserName.Contains(tb_UserName.Text));
                     }
                }
                else
                {
                    using(Site9527EntitiesDataContext dataContext=new Site9527EntitiesDataContext(SPContext.Current.Web.Url))
                    {
                        userList = dataContext.UserInfo;
                     }
                }           
               
                    foreach (var user in userList)
                    {
                        html.Append("<tr>");
                        html.Append("<td>"+user.Title);
                        html.Append("</td>");
                        html.Append("<td>" + user.UserName);
                        html.Append("</td>");
                        html.Append("<td>" + user.Gender);
                        html.Append("</td>");
                        html.Append("<td>" + user.Tell);
                        html.Append("</td>");
                        html.Append("<td>" + user.Adress);
                        html.Append("</td>");
                        html.Append("<td>" + user.ApprovalStatue);
                        html.Append("</td>");
                        html.Append("<td>" + 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>");
                    }
                
                td_Html.Text = html.ToString();
            }

     protected void bt_SaveClic(object sender, EventArgs e)
            {
                using (Site9527EntitiesDataContext dataContext = new Site9527EntitiesDataContext(SpContext.Current.Web.Url))
                {
                    UserInfoItem user = null;
                    user = dataContext.UserInfo.FirstOrDefault(i => i.Id == Convert.ToInt32(Request.QueryString["ID"]));
                    user.Title = this.tx_Title.Text;
                    user.UserName = this.tx_UserName.Text;
                    user.Adress = this.tx_adress.Text;
                    user.Gender = this.tx_Gender.Text;
                    user.Tell = this.tx_tell.Text;
                    dataContext.SubmitChanges(user);
                  
                   
                }
                base.Response.Redirent("UserInfoList.aspx");
            }
  • 相关阅读:
    windows10、windows server 2016激活方法
    .NET 和 .NET Core 使用 JWT 授权验证
    vs(vs2017、vs2019)离线安装包下载、制作
    VS顶部增加签名描述信息
    .NET WebAPI 跨域问题(has been blocked by CORS policy:No AccessControlAllowOgigin header is present on the requested resource)
    .Net 和 .Net Core 集成Swagger 以及配合JWT身份验证
    jQuery实现公告无限循环滚动
    甩掉 ashx/asmx,使用jQuery.ajaxWebService请求WebMethod,Ajax处理更加简练(转)
    JS和JQUERY常见函数封装方式
    第07组 Beta冲刺 (1/5)(组长)
  • 原文地址:https://www.cnblogs.com/liuwj/p/3881220.html
Copyright © 2011-2022 走看看