ECMASCript 之一 PeoplePicker,DatetimeControl,InPutFormText 控件的使用(添加时候) ECMAScript 更新 删除 DropDownLis绑...

前台:

<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    $("#<%=ddl_type.ClientID %>").change(function () {
                    if ($(this).val() == "") {
                        $(".tr_hidden").css("display", "none");
                    }
                    else {
                        $(".tr_hidden").css("display", "block");
                     }
                });


 

<table class="tab_style_add" style="border-left: 0px; border-right: 0px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="style1" style="padding-left: 20px;">标题 <span style="color: red;" title="这是必填字段">*</span></td>
<td class="style2"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;">类型</td>
<td class="td_style_right"> </td>
</tr>
<tr class="tr_hidden">
<td class="td_style_left" style="padding-left: 20px;">到期时间</td>
<td class="td_style_right"> </td>
</tr>
<tr class="tr_hidden">
<td class="td_style_left" style="padding-left: 20px;"> </td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"> </td>
<td class="td_style_right" style="height: auto; line-height: normal; padding: 0;">
<table id="tab_pics_add" style="width: 100%; border: 0px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="td_pics" style="border: 0; padding: 0;">
<ul class="t_box">
<li id="li_1"><img src="http://www.cnblogs.com/TNSSTAR/admin/" alt="" />  <input style="width: 386px;" type="text" /><input style="width: 386px; display: none;" type="text" /> <input style="width: 72px;" οnclick="uploadPicture(1)" type="button" value="上传" /> <a οnclick="AddPicRow(1)" href="javascript:void(0)">添加</a> <a οnclick="DelPicRow(1)" href="javascript:void(0)">删除</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"><span style="color: red;" title="这是必填字段">*</span></td>
<td id="td_publisher" class="td_style_right" style="padding-left: 5px;"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"> <span style="color: red;" title="这是必填字段">*</span></td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"></td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"></td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"></td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"></td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="padding-left: 20px;"> </td>
<td class="td_style_right"> </td>
</tr>
<tr>
<td class="td_style_left" style="border: 0;"> </td>
<td style="text-align: right; padding-top: 10px; border: 0;"><input id="btn_pvew" style="width: 88px; height: 23px; background-image: url(); background-color: transparent; border: 0;" οnclick="preview()" type="button" value" />     </td>
</tr>
</tbody>
</table>

 

 <script type="text/javascript">
            function ValiadData() {
                var isOk = false;
                var userName = $("div[id$='_txt_Name_upLevelDiv']").text();
//                var userName = document.getElementById('ctl00_m_g_7b548b26_b842_4e23_b974__4e23_b974_6535cfb5eb56_ASP_wpresources_teamactivityinfo_teamactivityinfoadd_ascx_txt_Name_upLevelDiv').innerText;
                var part = $("#<%=txt_Part.ClientID %>").val();
                var title = $("#<%=txt_title.ClientID %>").val();
                if (title == "") {
                    alert("请填写标题");
                    isOk = false;
                }
                else {
                    if (userName == "") {
                        alert("请填写");
                        isOk = false;
                    }
                    else {
                        if (part == "") {
                            alert("请填写");
                            isOk = false;
                        }
                        else {
                            var arr = $("#<%=hid_picIDs.ClientID %>").val().split(",");
                            for (var i = 0; i < arr.length; i++) {
                                if (arr[i] != "") {
                                    $(".t_box li input[type='text']").each(function (k) {
                                        var str = "";
                                        if ((k + 1) % 2 == 0) {
                                            if ($(this).val() == arr[i]) {
                                                str = $(".t_box li input[type='text']").eq(k - 1).val();
                                                if ($.trim(str) != "") {
                                                    updatePics(parseInt(arr[i]), str);
                                                }
                                            }
                                        }
                                    });

                                }
                            }
                           isOk = true;
                        }
                    }
               }
               return isOk;
           }
           function updatePics(Id, describe) {
             
               var context = new SP.ClientContext.get_current();
               var web = context.get_web();
               var list = web.get_lists().getByTitle('<%=AP %>');
               var picinfo = list.getItemById(Id);
               picinfo.set_item('Description', describe);
               picinfo.update();
               context.executeQueryAsync(Function.createDelegate(this, this.updatesuccess), Function.createDelegate(this, this.updatefailed));
           }
           function updatesuccess() {
             
           }
           function updatefailed(sender, args) {
              
           }


            function AddPicRow(obj) {
                $("#<%=hid_maxnum.ClientID %>").val(parseInt($("#<%=hid_maxnum.ClientID %>").val()) + 1);
                var tot_num = $("#<%=hid_maxnum.ClientID %>").val();
                $("#li_" + obj + "").after("<li id='li_" + tot_num + "'><img src=/>  <input  id='txtPic' style='width:386px;' type='text' /> <input  style='width:386px; display:none;' type='text' value='0' /><input type='button' value='上传' οnclick='uploadPicture(" + tot_num + ")' style='width: 72px' /> <a href='javascript:void(0)' οnclick='AddPicRow(" + tot_num + ")'>添加</a> <a href='javascript:void(0)' οnclick='DelPicRow(" + tot_num + ")'>删除</a></li>");
            }
            function DelPicRow(obj) {
                var picID = $("#li_" + obj + " input[type='text']").eq(1).val();
                DelTeamActivityByPicID(picID);
                var arr = $("#<%=hid_picIDs.ClientID %>").val().split(",");
                var newStr = "";
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i] != picID) {
                        newStr += arr[i] + ",";
                    }
                }
                $("#<%=hid_picIDs.ClientID %>").val(newStr);
                if ($(".t_box li").length > 1) {
                    $("#li_" + obj + "").remove();
                }
                else {
                    $("#li_" + obj + " img").attr("src", "");
                    $("#li_" + obj + " input[type='text']").eq(0).val("");
                    $("#li_" + obj + " input[type='text']").eq(1).val("");
                }
                
            }

            function DelPicID(Id) {
        
                var context = new SP.ClientContext.get_current();
                var web = context.get_web();
                var list = web.get_lists().getByTitle("<%=Lib %>");
                var itemToDelete = list.getItemById(Id);
                itemToDelete.deleteObject();
                context.executeQueryAsync(Function.createDelegate(this, this.deletesuccess),
                                  Function.createDelegate(this, this.deletefailed));
            }
            function deletesuccess() { }
            function deletefailed(sender, args) {
                
            }
           
        </script>

 

 

 

 

后台:::

 

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using Microsoft.SharePoint;

namespace TInfo
{
    public partial class oAdd : System.Web.UI.UserControl
    {
        private string _pageUrl = "/Pages/Teaist.aspx";
        [WebBrowsable(true)]
        [WebDisplayName("径")]
        [Personalizable(PersonalizationScope.Shared)]
        [SPWebCategoryName("自定义设置")]
        public string PageUrl
        {
            get { return _pageUrl; }
            set { _pageUrl = value; }
        }
        private string _activitytypename = "";
        [WebBrowsable(true)]
        [WebDisplayName("")]
        [Personalizable(PersonalizationScope.Shared)]
        [SPWebCategoryName("自定义设置")]
        public string Name
        {
            get { return _apename; }
            set { _apename = value; }
        }
        private string _activityPicLib =;
        //[WebBrowsable(true)]
        //[WebDisplayName("")]
        //[Personalizable(PersonalizationScope.Shared)]
        //[SPWebCategoryName("")]
        public string PicLib
        {
            get { return _PicLib; }
            set { _PicLib = value; }
        }
        BAO bao = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddl_TypeBind();
                dtc_publishtime.SelectedDate = DateTime.Now;
            }
        }
        protected void btn_OK_Click(object sender, EventArgs e)
        {
            bao = new BAO(string.Empty);
            Entity entity = new TEntity("", 1);
            entity.Type = ddl_type.SelectedValue;
            entity.Content = txt_details.Text;
            entity.CreateTime = DateTime.Now;
            entity.PublishPeople = GetPeopleEditorValue();//发布人
            entity.Draft = chk_isdrapt.Checked;
            entity.IsTime = dtc_activityendtime.SelectedDate;
            entity.IsVote = chk_isvote.Checked;
            entity.PublishPart = txt_Part.Text;
            entity.PublishTime = dtc_publishtime.SelectedDate;
            entity.Title = txt_title.Text;
            entity.ToTop = chk_istop.Checked;
            entity.ToTopUntilTime = dtc_topendtime.SelectedDate;
            int num = bao.InsertInfo(entity);
            if (num > 0)
            {
                int teamActivityID = CustomerConvert.ConvertNullToInt(bao.());
                string[] arr = hid_picIDs.Value.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] != "")
                    {
                        bao.UpdatePicsSetIDs(CustomerConvert.ConvertNullToInt(arr[i]), teamActivityID);
                    }
                }
                if (entity.Draft == true || Convert.ToDateTime(entity.PublishTime) > DateTime.Now)
                {
                    Common.Message(this.Page, "", PageUrl);
                }
                else
                {
                    Common.Message(this.Page, ", PageUrl);
                }
            }
            else
            {
                Common.Message(this.Page, ");
            }
        }
        private string GetPeopleEditorValue()
        {
            string strResult = string.Empty;
            ArrayList list = txt_Name.ResolvedEntities;
            foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)
            {
                if (p.EntityData["SPUserID"].ToString() != "")
                {
                    string userId = p.EntityData["SPUserID"].ToString();
                    string DisplayName = p.DisplayText.ToString();
                    strResult += userId + ";#" + DisplayName;
                    strResult += ",";
                }
            }
            return strResult;
        }
        private void ddl_TypeBind()
        {
            ddl_type.Items.Clear();
            bao = new BAO(string.Empty);
            List<string> list = new List<string>();
            list = bao.GetTypeList(Name);
            foreach (string type in list)
            {
                ddl_type.Items.Add(new ListItem(type, type));
            }
        }
        protected void btn_Cancel_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["Source"] != null)
            {
                Response.Redirect(Request.QueryString["Source"]);
            }
            else
            {
                Response.Redirect(PageUrl);
            }
        }
        protected string GetPublisher()
        {
            string publisher = "";
            if(GetPeopleEditorValue()!="")
            {
                string[] arr = GetPeopleEditorValue().Split(',');
                for (int i = 0; i < arr.Length; i++)
                { 
                    if(arr[i]!="")
                    {
                        string[] sArr = arr[i].Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
                        publisher += sArr[1] + "  ";
                    }
                }
            }
            return publisher;
        }
        protected string GetPublishDate()
        {
            if (dtc_publishtime.SelectedDate != null)
            {
                return dtc_publishtime.SelectedDate.ToShortDateString();
            }
            else
            {
                return "";
            }
        }
        protected string GetContent()
        {
            return txt_details.Text.ToString();
        }
    }
}

 

转载于:https://www.cnblogs.com/TNSSTAR/archive/2013/01/09/2852953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值