博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SharePointWebControls帮助类
阅读量:4135 次
发布时间:2019-05-25

本文共 1998 字,大约阅读时间需要 6 分钟。

using System;

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

namespace X.WebParts.UploadDocument

{
    class SharePointWebControls
    {
        /// <summary>
        /// 返回控件
        /// </summary>
        public static Control GetSharePointControls(SPField field, SPList list, SPListItem item, SPControlMode mode)
        {
            // 检查是否隐藏
            if (field == null || field.FieldRenderingControl == null || field.Hidden) return null;

            try

            {
                BaseFieldControl webControl = field.FieldRenderingControl;
                webControl.ListId = list.ID;
                webControl.ItemId = item.ID;
                webControl.FieldName = field.Title;
                webControl.ID = GetControlID(field);
                webControl.ControlMode = mode;

                return webControl;

            }
            catch (Exception ex)
            {
                var errorLabel = new Label
                {
                    ID = "ErrorLabel",
                    Text = string.Format("控件错误:<br/>{0}", ex)
                };
                return errorLabel;
            }
        }

        /// <summary>

        /// 返回控件对应的值
        /// </summary>
        public static object GetSharePointControlValue(ControlCollection Controls, SPField field)
        {
            if (Controls == null)
            {
                return null;
            }

            // 控件ID

            string controlID = GetControlID(field);

            foreach (Control control in Controls)

            {
                Control returnObject = control.FindControl(controlID);
                // 取值
                if (returnObject != null && returnObject is BaseFieldControl)
                {
                    return ((BaseFieldControl)returnObject).Value;
                }
            }

            return null;

        }

        /// <summary>
        /// 返回控件对应的值
        /// </summary>
        public static object GetSharePointControlValue(Control Control, string controlID)
        {
            if (Control == null)
            {
                return null;
            }
            Control returnObject = Control.FindControl(controlID);
            if (returnObject != null && returnObject is BaseFieldControl)
            {
                return ((BaseFieldControl)returnObject).Value;
            }

            return null;

        }

        public static Control FindControlRecursive(Control control, string controlID)
        {
            Control returnObject = control.FindControl(controlID);
            return returnObject;
        }

        private static string GetControlID(SPField field)

        {
            // unique id
            return System.Guid.NewGuid().ToString() + field.InternalName;
        }
    }
}

 

转载地址:http://xvpvi.baihongyu.com/

你可能感兴趣的文章
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>
HTTP和HttpServletRequest 要点
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
laravel 修改api返回默认的异常处理
查看>>
laravel事务
查看>>