| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 987 人关注过本帖
标题:设计状态下控件自动命名,按你设定的名字命名,对绑定数据库最有效
取消只看楼主 加入收藏
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
快速回复:设计状态下控件自动命名,按你设定的名字命名,对绑定数据库最有效
数据加载中...
 
   



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

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