Can't access controls programmatically when inside FormView control

N

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
 
G

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
 
G

Gardner Andersen

Oh, and you will have to use Invoke to call the delegate in order to get
the control to function properly....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top