简体   繁体   English

类型为“ DataControlLinkBut​​ton”的控件“ DataLoading1_gdvDataGroups_ctl01_ctl00”必须置于带有runat = server的表单标记中

[英]Control 'DataLoading1_gdvDataGroups_ctl01_ctl00' of type 'DataControlLinkButton' must be placed inside a form tag with runat=server

I'm trying to export the contents of an ASP.NET gridView control to an Excel spreadsheet. 我正在尝试将ASP.NET gridView控件的内容导出到Excel电子表格。 To do this I've been using the code on this page . 为此,我一直在使用此页上的代码。

When it gets to the RederControl(hw) line though my code blows up. 当它到达RederControl(hw)行时,尽管我的代码崩溃了。 I get an error like: 我收到如下错误:

GridView must be placed inside a form tag with runat=“server” even after the GridView is within a form tag

To solve this I found this answer . 为了解决这个问题,我找到了这个答案 However the main answer does not work and I think it is because my code is in an .ascx user control. 但是主要答案不起作用,我认为这是因为我的代码在.ascx用户控件中。 With that in mind I tried the solutions in the second highest rated answer. 考虑到这一点,我尝试了第二高评价答案的解决方案。

This time I get error relating to the DataControlLinkButtons similar to the title of this question. 这次我得到了与DataControlLinkBut​​tons有关的错误,类似于此问题的标题。

My gridview contains hyperlinks inside in the cells of one column. 我的gridview在一列的单元格中包含超链接。 I tried to remove them from their parent control prior to rendering with the following code (as per the second answer on that page) 我尝试在使用以下代码进行渲染之前将其从其父控件中删除(按照该页面上的第二个答案)

List<int> gridIndexes=new List<int>();
for (int i = 1; i < gdvDataGroups.Controls[0].Controls.Count-1; i++)
{   
    gridIndexes.Add(gdvDataGroups.Controls.IndexOf(gdvDataGroups.Controls[0].Controls[i].Controls[8].Controls[1]));
    gdvDataGroups.Controls.Remove(gdvDataGroups.Controls[0].Controls[i].Controls[8].Controls[1]);
}

but it didn't work for me and I got the same error. 但这对我不起作用,并且我遇到了同样的错误。

Any ideas of how to approach this? 关于如何解决这个问题的任何想法?

The gridView is as follows (with only the relevant 9th column included): gridView如下(仅包含相关的第9列):

 <asp:GridView ID="gdvDataFiles" SkinID="MediumSpace" runat="server" AutoGenerateColumns="False"
                        ShowHeader="true" Width="100%" OnPageIndexChanging="gdvDataFiles_PageIndexChanging"
                        AllowPaging="True" PageSize="20">
                        <Columns>                              
                            <asp:TemplateField HeaderText="Details" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("RequestPKID") == null ? "Not available" : "View" %>'
                                        NavigateUrl='<%# Eval("RequestPKID") == null ? "" : Eval("RequestPkid", "../Pages/BOLoadDetails.aspx?fileid={0}") %>'
                                        Style="padding-top: 4px; display: block" />
                                </ItemTemplate>
                            </asp:TemplateField>                                
                        </Columns>
                        <EmptyDataTemplate>
                            No data file loads found
                        </EmptyDataTemplate>
                    </asp:GridView>

Ok turns out that I needed to disable the sorting on the grid prior to rendering the spreadsheet. 确定,结果是我需要在呈现电子表格之前禁用网格上的排序。 I think it was the sort control buttons that were causing the problem. 我认为是导致问题的排序控制按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型为&#39;TextBox&#39;的控件&#39;ctl00_txtDebug&#39;必须放置在带有runat = server的表单标记中 - Control 'ctl00_txtDebug' of type 'TextBox' must be placed inside a form tag with runat=server 类型为“ RadioButton”的控件“ ctl00”必须置于带有runat = server的表单标记中 - Control 'ctl00' of type 'RadioButton' must be placed inside a form tag with runat=server 类型为&#39;TextBox&#39;的控件&#39;ctl07&#39;必须放置在带有runat = server的表单标记中。 - Control 'ctl07' of type 'TextBox' must be placed inside a form tag with runat=server. 'Button' 类型的控件 'ctl02' 必须放置在带有 runat=server 的表单标签内 - Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server 类型为“ HtmlEditorExtender”的控件必须放在带有runat = server的表单标签中 - Control of type 'HtmlEditorExtender' must be placed inside a form tag with runat=server 必须将带有'LinkBut​​ton'类型的控件xxx放在带有runat = server的表单标签内 - Control xxx of type 'LinkButton' must be placed inside a form tag with runat=server “SPGridView”类型的控件“testGridview”必须放置在带有 runat=server 的表单标签内 - Control 'testGridview' of type 'SPGridView' must be placed inside a form tag with runat=server &#39;TextBox&#39; 类型的控件 &#39;txtUserName&#39; 必须放置在带有 runat=server 的表单标签中 - Control 'txtUserName' of type 'TextBox' must be placed inside a form tag with runat=server 必须放置在带有 runat=server 的表单标签内 - Must be Placed Inside a Form Tag With runat=server 类型为&#39;TextBox&#39;的控件&#39;MainContent_forenameTxt&#39;必须放置在带有runat = server的表单标签中 - Control 'MainContent_forenameTxt' of type 'TextBox' must be placed inside a form tag with runat=server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM