Adding Datasource Property

Discussion in 'ASP .Net Building Controls' started by Steven W, Feb 15, 2005.

  1. Steven W

    Steven W Guest

    I need help with how to add a DataSource property to a composite control and
    then how to assign that property to the datasource of a datagrid.

    Thanks
    Steven W, Feb 15, 2005
    #1
    1. Advertising

  2. Steven W

    Wilco Bauwer Guest

    You could use aggregration, e.g.: create a composite control which
    contains a datagrid, and add a DataSource property which looks like:

    public object DataSource
    {
    get
    {
    this.myDataGrid.EnsureChildControls();
    return this.myDataGrid.DataSource;
    }
    set
    {
    this.myDataGrid.EnsureChildControls();
    this.myDataGrid.DataSource = value;
    }
    }

    You should create the datagrid in the CreateChildControls method.
    Wilco Bauwer, Feb 16, 2005
    #2
    1. Advertising

  3. Steven W

    Steven W Guest

    Thanks. That's a better solution than the path I was heading down.

    "Wilco Bauwer" wrote:

    > You could use aggregration, e.g.: create a composite control which
    > contains a datagrid, and add a DataSource property which looks like:
    >
    > public object DataSource
    > {
    > get
    > {
    > this.myDataGrid.EnsureChildControls();
    > return this.myDataGrid.DataSource;
    > }
    > set
    > {
    > this.myDataGrid.EnsureChildControls();
    > this.myDataGrid.DataSource = value;
    > }
    > }
    >
    > You should create the datagrid in the CreateChildControls method.
    >
    >
    Steven W, Feb 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    0
    Views:
    373
  2. Fred Dag
    Replies:
    1
    Views:
    397
    Karl Seguin [MVP]
    Jan 19, 2006
  3. Ken Varn
    Replies:
    5
    Views:
    405
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Mar 3, 2007
  4. Polaris431
    Replies:
    2
    Views:
    486
    Chris Dollin
    Nov 9, 2006
  5. Dave
    Replies:
    0
    Views:
    199
Loading...

Share This Page