ASP.Net 访问 FormView 控件中的子控件
我正在使用带有 EditItemTemplate 的 FormView 控件 (myFormView),其中包含许多子控件。当我使用标准 ASP.Net DropDownList 控件 (myDropList) 时,我可以使用下面的行获取对 myDropList 的引用:
((DropDownList)myFormView.FindControl("myDropList"))
我可以完全访问 myDropList 的属性并获取当前选定的值。这太棒了。
但是,我现在需要使用第 3 方子控件(此处找到的 FreeTextBox http://www.freetextbox.com) 在 FormView 控件中。我将 FreeTextBox 控件称为 myFTB,并且使用与上面类似的语句:
((FreeTextBox)myFormView.FindControl("myFTB"))
但是,这会返回 null,因此我能够检索其属性值。
有谁知道为什么它返回null?还有其他方法可以检索对控件的引用吗?
TIA
I'm using a FormView control (myFormView) with an EditItemTemplate which contains a number of child controls. When I use a standard ASP.Net DropDownList control (myDropList), I can obtain a reference to myDropList using the line below:
((DropDownList)myFormView.FindControl("myDropList"))
I can full access the properties of the myDropList and obtain the value currently selected. This is great.
However, I now need to use a 3rd party child control (FreeTextBox as found here http://www.freetextbox.com) in the FormView control. I've called the FreeTextBox control myFTB and I'm using a similar statement as above:
((FreeTextBox)myFormView.FindControl("myFTB"))
However, this returns null and thus I'm enable to retrieve property values for this.
Does anyone know why it is returning null? Is there some other way to retrieve the reference to the control?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要使用递归来查找控件层次结构中的控件。
尝试使用以下方法:
You will need to use recursion to find the control in the controls hierarchy.
Try using the following method:
您可以这样做来查找表单视图中的控件...
注意:下面的代码查找表单视图控件中的所有文本框
我希望它会对您有所帮助。
you can do like this to find controls in form view ....
NOte: The below code find the all text boxes inside the form view control
I hope it will helps you..