标题:设计状态下控件自动命名,按你设定的名字命名,对绑定数据库最有效
只看楼主
heyu52
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-11
 问题点数:0 回复次数:0 
设计状态下控件自动命名,按你设定的名字命名,对绑定数据库最有效
protected override void OnLoad(EventArgs e)
        {
           
            if (DesignMode)
            {
              base.OnLoad(e);
                _componentChangeService = this.Site.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (_componentChangeService != null)
                {
                    _ += new ComponentChangedEventHandler(componentChangeService_ComponentChanged);
                }
            }
        }


  #region IComponentChangeService
        public virtual void componentChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)
        {
            if (e.Member == null || == null) return;
            try
            {

                #region Location
                if (e.Member.Name == "Location" || e.Member.Name == "Name")
                {
                    return;
                }
                #endregion

                #region ChangeName
                Control control = as Control;
                if (control == null) return;

               

                INameCreationService namingService = this.Site.GetService(typeof(INameCreationService)) as INameCreationService;
                if (namingService != null && controlName != control.Name && control.Site != null)
                {
                    int i = 0;
                    while (!namingService.IsValidName(controlName))
                    {
                        controlName = "前缀" + i.ToString();
                        i++;
                    }
                    control.Site.Name = controlName;
                    return;
                }
                return;
                #endregion

            }
            catch
            {

            }
        }
        #endregion

[[it] 本帖最后由 heyu52 于 2008-4-16 00:07 编辑 [/it]]
搜索更多相关主题的帖子: 数据库 绑定 控件 状态 名字 
2008-04-16 00:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-209274-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.133939 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved