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,
SteveIn 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.
"Steve R" <anonymous@.discussions.microsoft.com> wrote in message
news:018101c39a63$a1354ad0$a501280a@.phx.gbl...
> 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.
>--Original Message--
>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.
This is definitely too racey for me. Someone mark this thread XXX please.
"Steve R" <anonymous@.discussions.microsoft.com> wrote in message
news:09de01c39a67$243a85f0$a001280a@.phx.gbl...
> 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.
> >--Original Message--
> >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.
So you were just BS'ing me on your original reply?
>--Original Message--
>This is definitely too racey for me. Someone mark this
thread XXX please.
Does anyone else have any advice?
Thanks,
Steve
>--Original Message--
>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
>.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment