Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用FindControl检索ListView_C#_Asp.net - Fatal编程技术网

C# 使用FindControl检索ListView

C# 使用FindControl检索ListView,c#,asp.net,C#,Asp.net,我试图从ascx控件检索两个ListView,以便将它们保存到PDF文件: <TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" /> 您的代码应更改为: var lv1 = (TagCloudControl)ListView.FindControl("ListView1"); var lv2 = (TagCloudControl)ListView.FindControl("ListView2"); 我从未见

我试图从ascx控件检索两个ListView,以便将它们保存到PDF文件:

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

您的代码应更改为:

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

我从未见过或使用过静态
FindControl()
方法

搜索当前命名容器 对于具有 指定的id参数

显然,如果您试图查找的ListView不在模板中,您应该能够在代码隐藏中直接访问它们。但是如果它在一个模板中,比如GridView的行中,那么您可以像这样访问它

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

嘿,我更新了我的代码,现在它说:'找不到类型或名称空间名称TagCloudControl,我仍然收到对象引用错误…@MiziaQ:右键单击
TagCloudControl
,然后选择Resolve,如果您引用了正确的程序集并且
ListView1
的类型是
TagCloudControl
,它应该通过使用或前缀为您提供一个选项。无论如何,我都会使用(ListView)。。。
ListView listView1 = (ListView) GridView1.Rows[0].FindControl("ListView1");