控件都找不到,怎么赋值?
贴menu.ascx出来看看

解决方案 »

  1.   

    这里是menu.ascx代码,在WEB页得了classid生成sql想把sql再传给它引用的第二个控件public partial class Control_MainMenu : System.Web.UI.UserControl
    {
        private int Classid;
        public string SetClassid
        {
            set
            {
                Classid =Convert.ToInt32( value);
            }
        }
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sql;
      
               sql = "select *from MLDG_Class where belong=" + Classid+" order by Orderby";//Wap
                   }    }
    }
      

  2.   

    这是menulist.ascx的代码,想通过第一个控代动态的给第二个控件赋setsql值,可我把第二个控件拉到第一个控件后,还是提示没有引用第二个控件.
    查了一些资料,好像是要委托,请问怎么委托啊public partial class Control_MainMenuList : System.Web.UI.UserControl
    {
        private string sql;
        public string Setsql
        {
            set
            {
                sql = value;
            }
            get
            {
                return sql;
            }
        }
       
        protected void Page_Load(object sender, EventArgs e)
        {
            
           
            if (IsPostBack)
            {
                Bind(sql);
            }    }
        private void Bind(string sql)
        {
            Db dbs = new Db();
            dbs.Conn("Dbstr");
            SqlDataReader Mydr = dbs.RunProcGetReader(sql);
            DataList1.DataSource = Mydr;
            DataList1.DataBind();
            Mydr.Close();
            Mydr.Dispose();
        }
    }
      

  3.   

    如果你使用的是 VS 2005.应该就是你开始的做法!不需要使用委托!如果你在一个控件的方法中要调用另外一个控件的方法需要使用委托.
    如果是VS 2003,可能需要在第一个控件中的.ascx (不是.ascx.cs) 中声明第二个控件的类!