Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindControl Need Help Finding Nested Controls

Status
Not open for further replies.

MxWade

Programmer
Aug 17, 2009
11
0
0
US
I am a newbie to ASP. I have researched my problem before asking this question and found several similar postings. I have not been able to find a solution that I can make work for my situation.

I have a FormView control (fvCityLookup) that is nested inside another FormView control (fvMain). I am trying to pull values from the labels in my nested FormView (fvCityLookup) and plug them into text boxes in the parent FormView control (fvMain).

My research on the subject has lead me to believe that I am not using FindControl properly.

I have tried several methods like the following but I can't get it to work:

Dim ZIPID As Label = Me.fvMain.Row.Controls.fvCityLookup.FindControl("eZIPIDLabel")
 
Break it apart into pieces first to be sure your findcontrol is working and returning what you expect.

Also, not sure where you are using findcontrol in your codebehind, but you should do it when you bind the formview.(DataBinding event)

First, find the nested formview(ftCityLookUp)
Make sure it is found.
Then, find the label within the found formview.

 
Thanks for your response. This is what I tried but it does not work. I get Object reference not set to an instance of an object.

Protected Sub fvMain_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles fvMain.DataBinding

Dim myFormView As FormView = Me.fvMain.FindControl("fvCityLookup")
Dim myLabel As Label = myFormView.FindControl("eZIPIDLabel")

Response.Write(myLabel.Text)
End Sub

 
Check the name of the nested control.
Can you post the HTML of your page?
 
Thanks - I put the same code inside the click event of a button (for ease of testing) and it works. This is the first time that I have ever seen anyone break it down as you suggested. It seems like a very good and straight forward approach to the problem.

Now I have to make it work on a SelectedIndexChanged event of a dropdown list that is inside the nested form. I will post again if I run into more problems.

Thanks Again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top