前台代码
<script type="text/javascript" src="/_layouts/15/VisualWebPartProject1/jquery.js"></script> <script type="text/javascript"> function Close() { var msg = $("input[title=aaa]").val();//获取title名为aaa的值 if (msg != "") { $("input[id*=hf]").val(msg); alert("操作成功") return true; } else { alert("值为空"); return false; } } </script> <a id="id" name="name">点击</a> <asp:Label ID="Label1" runat="server" Text="请选在推送到的文件路径"></asp:Label> <asp:DropDownList ID="dwlist" runat="server"> </asp:DropDownList> <asp:Button ID="Button1" runat="server" OnClientClick="return Close();" OnClick="Button1_Click" Text="推送" /> <asp:HiddenField ID="hf" runat="server" />
后台代码
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { InitDropDownList(); } } protected void Button1_Click(object sender, EventArgs e) { //Page.ClientScript.RegisterStartupScript(GetType(), "", "alert(‘值:" + hf.Value + "‘);", true); NewMethod(); ClientScriptManager cs = Page.ClientScript; Page.Response.Redirect("http://amid01110/_layouts/15/start.aspx#/Lists/test2/AllItems.aspx"); } private void NewMethod() { using (SPSite site = new SPSite("http://amid01110/")) { SPWeb web = site.RootWeb; string id = Page.Request["ID"]; string text = Page.Request["aaa"]; SPListItem li = web.Lists["test2"].GetItemById(int.Parse(id));//实例化要添加的列的值如果部署到别的列表里就更改test2这个列表名 web.AllowUnsafeUpdates = true;//设置允许更改 SPList list = web.Lists[dwlist.SelectedItem.Text];//实例化列表名称 SPListItem item = list.Items.Add(); item["Title"] = li["Title"];//向列表添加为Call Tom item["aa"] = hf.Value;//通过jq取得值 item["同意"] = li["同意"]; item["时间"] = li["修改时间"]; item["选择用户"] = li["选择用户"]; item.Update();//更新 //web.Dispose(); //site.Dispose(); li.Delete();//删除此项 } } public void InitDropDownList() { using (SPSite site = new SPSite("http://amid01110/")) { ListItemCollection LIColl = new ListItemCollection(); ArrayList list = new ArrayList(); SPWeb web = site.RootWeb; LIColl.Add("wd"); LIColl.Add("test"); LIColl.Add("test2"); //foreach (SPList ls in web.Lists) //{ // //Page.Response.Write(ls.Title + "<br/>");//获取后显示在页面上 // LIColl.Add(ls.Title);//将数据保存list中 //} dwlist.DataSource = LIColl;//绑定 dwlist.DataBind();//绑定 } }