• 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");
            }
  • 相关阅读:
    vscode设置成中文
    PHP中关于foreach使用引用变量的坑
    phpstorm更换主题
    常用phpstorm快捷键
    记录ThreadPoolTaskExecutor线程池的在项目中的实际应用,讲解一下线程池的配置和参数理解。
    Spring,SpringMvc配置常见的坑,注解的使用注意事项,applicationContext.xml和spring.mvc.xml配置注意事项,spring中的事务失效,事务不回滚原因
    nginx代理配置 配置中的静态资源配置,root 和 alias的区别。启动注意事项
    session图片验证码,页面和请求是两个地址。android手机好用,iphone 失效。
    《Inside C#》笔记(十五) 非托管代码 下
    日常问题总结 三
  • 原文地址:https://www.cnblogs.com/liuwj/p/3881220.html
Copyright © 2020-2023  润新知