zoukankan      html  css  js  c++  java
  • ItemAdding实现数据验证中文字段,properties.AfterProperties值为null的问题

    最近写事件接收器,发现中文字段如果直接用properties.AfterProperties[“申请人"]这样获取的值为null,无法得到值。后拉忽然发现用英文字段可以得到值。难道中文字段需要编码?经过测试果真如此。

    代码部分如下:

    public override void ItemAdding(SPItemEventProperties properties)
    {
           base.ItemAdding(properties);
           //得到站点
            SPWeb web = properties.OpenWeb();
           //如果web不为空
            if (web != null)
            {
                 //得到列表
                   SPList list = web.Lists[properties.ListId];
                  //如果列表不为空
                   if (list != null)
                  {
                       //得到字段
                       string fieldName = list.Fields.GetField(WorkLeaveConfig.WorkLeave_Title).InternalName;
                       //得到值
                       string WorkTitle = properties.AfterProperties[fieldName] == null ? string.Empty : properties.AfterProperties[fieldName].ToString();
                       //得到值
                       if (WorkTitle.IndexOf("测试") >= 0)
                     {
    
                           properties.ErrorMessage = "无法请假!";
                           properties.Cancel = true;
                      }
                 }
            }
               
     }
    效果图如下:
    clip_image002
  • 相关阅读:
    light_oj 1197 区间素数筛
    light_oj 1213
    light_oj 1220 素数分解
    bestcoder#43 1002 在数组中找两个数的和取模的最大值 二分
    6月7日 bc总结
    省赛总结
    二分图最大点权独立集 二分图最大点权覆盖
    终于能理解kmp算法了
    hduoj2087 统计串t在串s中出现的次数,重叠不算 KMP
    带权二分图的最大权匹配 KM算法模版
  • 原文地址:https://www.cnblogs.com/love007/p/2471261.html
Copyright © 2011-2022 走看看