Findcontrol in a FormView

Okay I have tried everything..... I've spent hours researching this to no avail

I need to set the property enabled of a drop down box in a Formview to false.

Dim dl as DropDownList

dl = FormView1.findControl("EmpDrop")

dl.Enabled = False

Does not work

----------------------------------------------------------------------------

Dim dl as DropDownList

dl = findControl("FormView1.EmpDrop")

dl.Enabled = False

Does Not work

----------------------------------------------------------------

Dim fv as Formview

Dim dl as DropDownList

fv = findControl("FormView1")

fv.enabled = True ' just to see if I got this error.. and went past it so is okay I guess

dl = fv.findControl("EmpDrop")

dl.Enabled = False

Does not work..

What the heck am I missing here

I even set it up so that there is ONLY a formview and an DropDown list on it.

I need this badly as I am almost done developing something and this is the last thing I have to do...



Answer this question

Findcontrol in a FormView

  • Dan Smithtown

    i am in the same problem

    this is my suggest

    Protected Sub FormView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBinding

    If FormView1.CurrentMode = FormViewMode.Edit Then

    Dim ddl As DropDownList

    ddl = FormView1.FindControl("dropdownlist1")

    ddl.Items.Insert(0, New ListItem("-select from list-", "0"))

    End If

    End Sub



  • Venu Yankarla

    pl. call FindControl in the Event Handler for ItemCreated of FormView.


  • CorkChop

    i ran into the same issue. seems as though the findcontrol function will only find controls in it's 'scope' ie: whatever mode/template the formview is currently in.

    try changing the formview mode to the appropriate template and try that.

    ok, now i have a question relating to the above as well. i want to be able to get the 'onSelected' event while the formview is in insert mode. is this possible and if so how

    i can get it to fire while in edit mode fine, just not in insert mode.

    -Scott

    oh, and try this to find the control once it's in the correct mode:

    Dim dd As Dropdown = CType(FormView1.FindControl("yourdropdownhere"), Dropdown)


  • bkrgr1

    Sorry that was one example I did not put in there. No that does not work either. I believe it has something to do with the fact that it is in the EditItemTemplate within the FormView. although when I place that qualifier in it, the only method available is InstantiateIn.

    No one has ever had to do this before Must be that someone has.

    Thanks for your help


  • catalyst

    hi,

    i have used something like that b4, in asp.net 1.1 i'm not sure if it will work with you or not but you can give it a try

    '-- then next code is to locate the button(called p1) in the place holder control (called pagebuttons) and
    '-- to conver it to button and to style it

    Dim FirstButton As Button
    FirstButton = CType(PageButtons.FindControl("P1"), Button)
    FirstButton.Style("background-color") = "#990000"
    FirstButton.Style("color") = "#FFFFFF"

    so i guess the thing that you missing is the

    mydropdownlist = Ctype(FormView1.findControl("EmpDrop"), Dropdownlist)

    hope this will help



  • lc247

    pl. call FindControl in the Event Handler for ItemCreated of FormView.


  • Findcontrol in a FormView