必须将带有'GridView'类型的控件'GridView1'放在带有runat = server的表单标签内。 [英] Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

查看:70
本文介绍了必须将带有'GridView'类型的控件'GridView1'放在带有runat = server的表单标签内。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将datagrid导出为ex​​cel时,我的gettig错误如下所示。



'GridView'类型的控件'GridView1'必须放在带有runat =的表单标签内服务器。



看到我的代码:

解决方案

正如我所想,你的代码背后证实了你确实是导出你的网格。



当一个人试图将GridView控件导出为Word,Excel,PDF,CSV或任何其他格式时,会发生上述异常。这里.net编译器认为控件没有添加到表单并被渲染,因此即使你的GridView控件在runat =server的表单中,它也会抛出此错误。



你必须通过覆盖 VerifyRenderingInServerForm 事件告诉编译器显式地呈现控件。

喜欢:

  public  覆盖  void  VerifyRenderingInServerForm(Control control)
{
//
}





这将确认在运行时为指定的ASP.NET服务器控件呈现HtmlForm控件

在此处查看活动详情: Page .VerifyRenderingInServerForm方法 [ ^ ]


< blockquote>我遇到过类似的问题很多次,当你将EnablePaging或EnableSorting设置为true时会发生这种情况。

解决方案是在导出之前禁用排序和/或分页,并在之后重新启用它们出口。


I am gettig error as below when export datagrid to excel.

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

see my code :

解决方案

As I thought, your code behind confirmed it that you indeed are exporting your grid.

The above exception occurs when one tries to export a GridView control to Word, Excel, PDF, CSV or any other formats. Here the .net compiler thinks that the control is not added to the form and is rendered, hence it throws this error even if your GridView control is inside a form with runat = "server".

You have to tell the compiler that the control is rendered explicitly by overriding the VerifyRenderingInServerForm event.
Like:

public override void VerifyRenderingInServerForm(Control control)
{
   //
}



This will confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time
Look at the event detail here: Page.VerifyRenderingInServerForm Method[^]


I have encountered similar problems a number of times and it occurs when you have EnablePaging or EnableSorting set to true.
The solution would be to disable sorting and/or paging before the export and reenable them after the export.


这篇关于必须将带有'GridView'类型的控件'GridView1'放在带有runat = server的表单标签内。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆