开发者

Find a textbox inside panel which is inside FormView

开发者 https://www.devze.com 2023-04-11 01:16 出处:网络
The formview has more than 1 P开发者_StackOverflowanels. My textbox is in the first panel. If I use this

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消