原贴:已结
http://community.csdn.net/Expert/topic/5235/5235350.xml?temp=.8994562
首先感谢一下原贴的:noood(肥田) 不过VB的我不太懂,你那个我改不了环境:
页面index.aspx包含uc1,uc2,uc3,uc4....
index.aspx 定义了一个DataSet ds和string sql;
要求是:
里面的uc1,uc2... 里面的控件可以绑定aspx里的dt和获得sql的值谢谢

解决方案 »

  1.   

    每个用户控件声明一个public DataTable 的变量 .
    调用的时候赋值。如:
    调用的aspx中,先查询
    DateTable dt =//查询
    this.uc1.dt =  dt;
    this.uc2.dt =  dt;
    this.uc3.dt =  dt;
    在每个用户控件中使用dt绑定控件。
      

  2.   

    我喜欢在ascx里写个方法,然后在aspx调用时,把DataSet 和string作为方法的参数传递过去。
      

  3.   

    tO:lincai(隐身) 这种方法更好。如:this.uc1.BindData(ref dt);
    this.uc2.BindData(ref dt);
    this.uc3.BindData(ref dt);
    this.uc4.BindData(ref dt);
      

  4.   

    设计ascx的时候输出做好了
    输入也要多考虑啊,不同情况下的
    各种可能性都要尽量想好
    ascx肯定是要大量重用的,
    更要多想想,想好了才写
      

  5.   

    REL:3楼4楼
    如:
    this.uc1.BindData(ref dt);
    this.uc2.BindData(ref dt);
    this.uc3.BindData(ref dt);
    this.uc4.BindData(ref dt);
    是不是
    ascx:
    注册事件
    load
    {
      调用事件
    }
    aspx
    {
      添加事件
    }
    事件
    {
       ascx.???.DataBind();
    }
    ---------------------------
    上面这样好像只是对用户控件进行绑定
    而我要的是ascx得到aspx的DataSet dt有没有这种方法:
    asdx
    load
    {
      if(dt!=null)
      {
        datalist.datasocus=ds
        datalist.DataBind;
      }
    }
    aspx:
    public dataset ds
    load
    {
       ds=Get(sql)//这里返回一个DataSet
    }