compdept.ascx.cspublic partial class CompDept : System.Web.UI.UserControl
    {
        private string _compid;
        private string _deptid;
        public string compId
        {
            get
            {
                return _compid;
            }
            set
            {
                this._compid = value;
            }
        }        public string deptId
        {
            get
            {
                return _deptid;
            }
            set
            {
                this._deptid = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDrop();
            }
        }
        private void BindDrop()
        {
            this.dropComp.DataSource = HR.GetComp();
            this.dropComp.DataBind();
            BindDep(this.dropComp.SelectedValue);
            this._compid = this.dropComp.SelectedValue;
            this._deptid = this.dropDept.SelectedValue;
        }
        private void BindDep(string compId)
        {
            DataTable dept = HR.GetDept();
            DataView deptView = new DataView(dept);
            deptView.RowFilter = "COMP = " + compId;
            this.dropDept.DataSource = deptView;
            this.dropDept.DataBind();
            this.dropDept.Items.Insert(0, new ListItem("----全部显示----", ""));
            this._compid = this.dropComp.SelectedValue;
            this._deptid = this.dropDept.SelectedValue;
        }
        protected void dropComp_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindDep(this.dropComp.SelectedValue);
        }
    }

解决方案 »

  1.   

    dept.aspx.cspublic partial class dept : System.Web.UI.Page
        {
            
            protected void Page_Load(object sender, EventArgs e)
            {
                SysUtils.ChkAdminRight();
                if (!IsPostBack)
                {
                    SetMsgTab();
                    BindGrid();
                }
            }
            private void SetMsgTab()
            {
                SysConfiguration.SetRes();
                this.MsgTab1.TUrl = HR.UnitLink;
                this.MsgTab1.TText = HR.UnitTitle;            this.MsgTab1.Title = "<img src=/es/img/jginf.gif border=0 align=absmiddle>组织结构";
                this.MsgTab1.SetHotTab(1);
            }
            private void BindGrid()
            {
                string compId = compDept1.compId;/////////这里总是Null值.???
                string deptId = compDept1.deptId;////////这里总是Null值.???
                DataView dv = HR.GetDept().DefaultView;
                dv.RowFilter = "COMP = " + compId;
                if (deptId != "")
                {
                    this.dgdDep.DataSource = HR.GetDept(int.Parse(deptId));
                }
                else {
                    this.dgdDep.DataSource = dv;
                }
                this.dgdDep.DataBind();
            }        protected void cmdQuery_Click(object sender, ImageClickEventArgs e)
            {
                BindGrid();
            }
        }
      

  2.   

    你在页面上是否已经赋值
    就比如<yourControl:compDept id="compDept1" compId="123" deptId="456">
      

  3.   

    用的是vs03 ?
    05在cs中是可以直接调用的
    03好像 要手动 加上private CompDept compDept1;然后 在直接访问就可以了
      

  4.   

    回4楼,在页面上没有赋值啊,那些值要通过选择Dropdownlist才得到的啊
      

  5.   

    所以 这就是问题所在了啊 
    在你的page_load里面根本就没有Dropdownlist什么事情 这两个属性当然就是空了啊 
      

  6.   

    说得不对了 
    没仔细看清楚
    现在的问题应该是 你的Dropdownlist在刚刚加载的时候 设置了Selected的item没有啊