Home All Groups Group Topic Archive Search About

Can't access controls programmatically when inside FormView control

Author
17 Sep 2006 2:21 AM
nicomp
Hello,

I have a FormView control that has a CheckBoxList in the Item
template...

I wrote this code to access a CheckBoxList in a FormView template...

dim foo as checkboxlist
foo =  Me.fvVehicle.FindControl("cblSafety")
foo.items(0).selected = true

This code does not set the check box in the cbl. No errors, but nothing
happens.

If the checkBoxList is moved out of the the FormView control, then this
works fine:

cblSafety.Items(0).selected = true

But I can't refernence the cbl control by name if it's in the FormView.
Therefore this approach will not work at all.

I also tried it by ID and it didn't work either...
dim foo as Integer
foo = me.fvVehicle.FindControl("cblSafety").ID
dim bar as CheckBoxList
bar = me.FindControl(foo)
bar.Items(0).Selected = True


Any thoughts?

Bill
Cincinnati, OH USA

Author
17 Sep 2006 3:41 AM
Gardner Andersen
Ten to one you need to use a delegate to make the call.

Check your help file and google for delegate(s) information, then give it a
try.  I'm guessing it will fix your problem.

Gardner
Author
17 Sep 2006 3:43 AM
Gardner Andersen
Oh, and you will have to use Invoke to call the delegate in order to get
the control to function properly....
Author
17 Sep 2006 10:42 AM
Theo Verweij
Maybe this will help: http://odetocode.com/Articles/116.aspx

nicomp wrote:
Show quoteHide quote
> Hello,
>
>  I have a FormView control that has a CheckBoxList in the Item
> template...
>
> I wrote this code to access a CheckBoxList in a FormView template...
>
> dim foo as checkboxlist
> foo =  Me.fvVehicle.FindControl("cblSafety")
> foo.items(0).selected = true
>
> This code does not set the check box in the cbl. No errors, but nothing
> happens.
>
> If the checkBoxList is moved out of the the FormView control, then this
> works fine:
>
> cblSafety.Items(0).selected = true
>
> But I can't refernence the cbl control by name if it's in the FormView.
> Therefore this approach will not work at all.
>
> I also tried it by ID and it didn't work either...
> dim foo as Integer
> foo = me.fvVehicle.FindControl("cblSafety").ID
> dim bar as CheckBoxList
> bar = me.FindControl(foo)
> bar.Items(0).Selected = True
>
>
> Any thoughts?
>
> Bill
> Cincinnati, OH USA
>