zoukankan      html  css  js  c++  java
  • asp.net 动态加载的用户控件属性传id值问题

    页面部分代码:

    ArrayList url = new ArrayList();   // 模块路径
     ArrayList md=new ArrayList();   //模块id


            url = jyoauser.return_rolemodel(role_id, system_id);//返回角色对应模块url
            md = jyoauser.return_rolemodel2(role_id,system_id);//返回角色对应模块id

            for (int u = 0; u < url.Count; u++)
            {

     Control uc = new Control();
      uc = Page.LoadControl(url[u].ToString());
            

           

                Type pType = uc.GetType();//自动获得加载控件的类型
              
          PropertyInfo pi=pType.GetProperty("modelid"); //自动获得加载控件的属性 当然这里如果是方法用pType.GetMethod

          pi.SetValue(uc, md[u].ToString(), null); //把控件的模块id值传给控件的modelid属性


        
                test.Controls.Add(uc);
             
            }

    每个表示模块的控件是从数据库动态加载
    一个控件部分代码:
      private int _modelid;控件的模块id
      public int modelid
      {
      get { return this._modelid; }
      set { this._modelid = value; }
      }

  • 相关阅读:
    4.20 每日一练
    4.19 每日一练
    4.18 每日一练
    Python函数初
    Python的文件操作
    python购物车
    python深浅拷贝,集合以及数据类型的补充
    Python 代码块 小数据池
    Python字典
    Python 列表操作
  • 原文地址:https://www.cnblogs.com/hjtdlx/p/2226569.html
Copyright © 2011-2022 走看看