The formview has more than 1 P开发者_StackOverflowanels. My textbox is in the first panel. If I use this
TextBox myTxtBox = (TextBox)myformView.Row.FindControl("pnlID").FindControl("mytextbox"); <- does not work
Panel mypanel = (Panel)myformView.Row.FindControl("pnlID"); <- this works
TextBox myTxtBox = (TextBox) FindControlRecursive(mypanel,'mytextbox'); <-- this does not work
Can someone help? As as side question, I used a function FindControlIterative but I do not know which references to include for LinkedList
The following works for me:
Markup
<asp:FormView ID="formView1" runat="server">
<ItemTemplate>
<asp:Panel ID="pnlID" runat="server">
<asp:TextBox ID="mytextbox" runat="server"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:FormView>
Code behind
TextBox myTxtBox = (TextBox)FindControlRecursive(formView1,"mytextbox");
My answer: @jdavies solution is right. I was passing the wrong control to the function. I realized my formView1 was actually inside another panel, thus formview was not directly visible to code behind.
精彩评论