我正在尝试从 ascx 控件中检索两个 ListView ,以便将它们保存到 PDF 文件中:
<TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" />
我收到以下错误:TagCloudControl1 是一个字段,但像类型一样使用,非静态字段、方法或属性需要对象引用...感谢您的帮助!
ListView lv1 = (TagCloudControl1)ListView.FindControl("ListView1");
ListView lv2 = (TagCloudControl1)ListView.FindControl("ListView2");
lv1.RenderControl(htWriter);
lv2.RenderControl(htWriter);
最佳答案
我从未见过或使用过静态 FindControl()
方法。
Searches the current naming container for a server control with the specified id parameter.
显然,如果您尝试查找的 ListView 不在模板中,您应该能够在代码隐藏中直接访问它们。但是如果它在模板中,例如 GridView 的行,那么您可以像这样访问它。
ListView listView1 = (ListView) GridView1.Rows[0].FindControl("ListView1");
关于c# - 使用 FindControl 检索 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984999/