Accessing controls within a FormView and Panel

mattlaltman
mattlaltman used Ask the Experts™
on
This is probably easy but I can't figure it out (newbie).  I have a Drop down list that's located within a FormView and within a panel.  When I try to access the control from the code behind page, it doesn't recognize it.  I'm assuming it's because it's within other controls.  I'm not sure what the proper way is to access it.  

Thanks for your help in advance!
Here is my asp.net code:
<asp:FormView
    id="frmCreateDist"
    DataSourceID = "srcCreateDist"
    DefaultMode = "Insert"
    Runat="server">
    <InsertItemTemplate>
    
    <asp:Panel 
        ID="Panel1" 
        GroupingText="Create Dist"
        runat="server">

        <br />

        <asp:DropDownList 
            ID="ddlStateList" 
            runat="server"/>


    </asp:Panel>
   </InsertItemTemplate>
</asp:FormView>



Here is my code behind page.  ddlStateList is unrecognizable:


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ddlStateList.DataSource = StateManager.getStates()
        ddlStateList.DataTextField = "FullAndAbbrev"
        ddlStateList.DataValueField = "Name"
        ddlStateList.DataBind()
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Developer
Commented:
Dim dlst as DropDownList
dlst = cType( frmCreateDist.findControl("Panel1").findControl("ddlStateList"), DropDownList )

Author

Commented:
thank you!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial