Search code examples
asp.netuser-controlsobjectdatasource

ASP.Net User Control


I'm trying to build an ASP.net user control that uses a Repeater to iterate over a number of items in an ObjectDataSource that I need to pass in to the user control. I'm not sure how to pass the object data source in though. Any one know how to do this?


Solution

  • You can create a property in the user control and pass it to the repeater.

    public class CustomUserControl
    {
      private Repeater repeater;
    
      public ObjectDataSource DataSource
      {
        get
        {
          return this.repeater.DataSource;
        }
        set
        {
          this.repeater.DataSource = value;
        }
      }
    }