DropDownList based on data Control inside another Control

Last post 11-28-2006 2:36 AM by emmav. 4 replies.

Sort Posts:

  • DropDownList based on data Control inside another Control

    11-24-2006, 9:45 AM
    • Member
      35 point Member
    • emmav
    • Member since 11-24-2006, 9:40 AM
    • Posts 7

    Ok, so I have a FormView with a Customer dropdown, and a Location dropdown. The Location dropdown is dependant on the Customer dropdown.

    "Easy," I think. But no. The Location drop down works when it and the Customer dropdown is placed outside the Formview. But when they are both inside the formview they don't as they aren't in the right scope(or whatever). I've tried CustomerDropDown, but to no avail.

    Anyone have any ideas on how to manage this?

  • Re: DropDownList based on data Control inside another Control

    11-24-2006, 9:11 PM
    • Member
      300 point Member
    • cwlaualex
    • Member since 01-17-2006, 2:46 AM
    • HKSAR
    • Posts 97
    Do you use FormViewName.FindControl to locate your second DDL? You need to use FindControl for every controls inside the FormView.
    Alex Lau
    HKSAR
  • Re: DropDownList based on data Control inside another Control

    11-27-2006, 2:53 AM
    • Member
      35 point Member
    • emmav
    • Member since 11-24-2006, 9:40 AM
    • Posts 7

    By doing it programatically rather than using the designer?

    I tried using FindControl as in: 

    DropDownList Customer = (DropDownList) FormView1.FindControl("KundeDropList");
      But it won't have any of it, saying "Object reference not set to an instance of an object."
  • Re: DropDownList based on data Control inside another Control

    11-27-2006, 9:33 PM
    • Member
      300 point Member
    • cwlaualex
    • Member since 01-17-2006, 2:46 AM
    • HKSAR
    • Posts 97

    Maybe you need to post some of your code here. The FindControl function should return the required DropDownList.

    Alex Lau
    HKSAR
  • Re: DropDownList based on data Control inside another Control

    11-28-2006, 2:36 AM
    Answer
    • Member
      35 point Member
    • emmav
    • Member since 11-24-2006, 9:40 AM
    • Posts 7
    What I couldn't do with FindControl I could do with this function:
    1      protected static Control FindControlRecursive(string Id, Control Root)
    2 {
    3 if (Root.ID == Id)
    4 return Root;
    5 6 foreach (Control Ctl in Root.Controls)
    7 {
    8 Control FoundCtl = FindControlRecursive(Id, Ctl);
    9 if (FoundCtl != null)
    10 return FoundCtl;
    11 }
    12 return null;
    13 }

    (lifted from http://www.west-wind.com/WebLog/posts/5127.aspx) and using  

    1    DropDownList Customer = FindControlRecursive("KundeDropList", FormView1) as DropDownList;
    And setting selectedvalue manually.
    Thanks for your help cwlaualex! (That's quite a nick, does it mean anything? Different language?)
     
Page 1 of 1 (5 items)