我正在尝试从一个ascx控件中检索两个列表视图,以便将它们保存到PDF文件中:
<TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" />我得到了以下错误: TagCloudControl1是一个字段,但它像类型一样使用,并且非静态字段、方法或property...Thanks需要一个对象引用才能获得帮助!
ListView lv1 = (TagCloudControl1)ListView.FindControl("ListView1");
ListView lv2 = (TagCloudControl1)ListView.FindControl("ListView2");
lv1.RenderControl(htWriter);
lv2.RenderControl(htWriter);发布于 2011-02-13 23:54:56
我从未见过或使用过静态FindControl()方法。
From MSDN for FindControl()
在当前命名容器中搜索具有指定id参数的服务器控件。
显然,如果您试图定位的列表视图不在模板中,您应该能够在代码隐藏中直接访问它们。但是如果它在模板中,比如GridView's Row,那么你可以像这样访问它。
ListView listView1 = (ListView) GridView1.Rows[0].FindControl("ListView1");发布于 2011-02-13 23:33:59
您的代码应更改为:
var lv1 = (TagCloudControl)ListView.FindControl("ListView1");
var lv2 = (TagCloudControl)ListView.FindControl("ListView2");https://stackoverflow.com/questions/4984999
复制相似问题