Getting ListView with FindControl

I am trying to extract two lists from an ascx control to save them to a PDF file:

<TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" />

I get the following error: TagCloudControl1 is a field, but is used as a type, and an object reference is required for a non-static field, method or property ... Thanks for your help!

ListView lv1 = (TagCloudControl1)ListView.FindControl("ListView1");
ListView lv2 = (TagCloudControl1)ListView.FindControl("ListView2");

lv1.RenderControl(htWriter);
lv2.RenderControl(htWriter);
+3
source share
2 answers

I have never seen or used a static method FindControl().

From MSDN to FindControl ()

Searches for the current naming container for server management using the specified id parameter.

Obviously, if the lists you are trying to find are not in the template, you must have access to them directly in encoding. But if it's in a template like GridView Row, you can access it like this.

ListView listView1 = (ListView) GridView1.Rows[0].FindControl("ListView1");
+1

:

var lv1 = (TagCloudControl)ListView.FindControl("ListView1");
var lv2 = (TagCloudControl)ListView.FindControl("ListView2");
0

Source: https://habr.com/ru/post/1791842/


All Articles