Web Custom Control

  • Thread starter Thread starter Steve R
  • Start date Start date
S

Steve R

I am building a web custom control that encapsulates a
series of dropdowns, buttons, etc. It is derived from a
WebControl. I have the control built so that it renders
properly. Now I am defining the public Bind() method so
that I can connect to various datasources via a
connection property I have defined.

The problem is that in my public Bind() method when I am
populating a dropdown using Datasource and DataBind, the
dropdown is not populated. I have the dropdown
(ddlbProduct) defined at the class level where I am
creating a new instance of the dropdown:

DropDownList ddlbProduct= new DropDownList();

I am placing it on my control in the CreateChildControls
() override like this:

thePageView.Controls.Add(ddlbProduct); // I'm putting the
dropdown inside of a PageView

I am binding the dropdown to a DataTable in my public Bind
() function like this:

ddlbProduct.DataSource = theDataSet.Tables[0];
ddlbProduct.DataValueField = "product_line";
ddlbProduct.DataTextField = "product_line_name";
ddlbProduct.DataBind();

When I step it through in debug I can see the instance of
ddlbProduct get populated correctly on the
ddlbProduct.DataBind() call. The instance that is
rendered on the page is not populated though. The only
time I am implicitly instantiating it is at the class
level.

I know this is probably an easy one. This is my first
custom control.

Thanks,

Steve
 
I changed it so that I am calling a private method from
my public Bind() method. Still doesn't work.

I need a public method to do the bind so that I can set
the connection property first.
 
In your public Bind() method you have to go private. This is not suitable to
be done publicly. It should only be done behind closed doors by consenting
adults.
 
Back
Top