帮帮忙啊,什么没人理我啊,datagridtoexcel问题

wyp0623 2004-06-30 09:59:02
aspx文件:

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
Text="Button"></asp:Button>
<asp:DataGrid id="WU1DataGrid1" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 64px" runat="server"
AllowSorting="True" AutoGenerateColumns="True" AllowPaging="True">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="btnview" Runat="server" CausesValidation="False" CommandName="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>
</form>




private void Button1_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer=true;
Response.ContentType="application/vnd.ms-excel";
Response.Charset="";
this.EnableViewState=false;

System.IO.StringWriter oStringWriter=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter=new System.Web.UI.HtmlTextWriter(oStringWriter);

this.ClearControls(WU1DataGrid1);
WU1DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();

}
//*********************************************************************************************************
private void ClearControls(Control control)
{
for(int i=control.Controls.Count-1;i>0;i--)
{
ClearControls(control.Controls[i]);
}
if(!(control is TableCell))
{
if(control.GetType().GetProperty("SelectedItem")!=null)
{
LiteralControl literal=new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text=(string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch
{

}
control.Parent.Controls.Remove(control);
}
else
if(control.GetType().GetProperty("Text")!=null)
{
LiteralControl literal=new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text=(string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}



出现错误:
Exception Details: System.Web.HttpException: Control 'WU1DataGrid1__ctl2__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.

Source Error:


Line 504:
Line 505: this.ClearControls(WU1DataGrid1);
Line 506: WU1DataGrid1.RenderControl(oHtmlTextWriter);
Line 507: Response.Write(oStringWriter.ToString());
Line 508: Response.End();


Source File: c:\inetpub\wwwroot\xxh\dlsbh\main.aspx.cs Line: 506

可我明明都已放在<form runat=server>中的啊
帮帮忙,各位!!
...全文
113 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cody416 2004-07-01
  • 打赏
  • 举报
回复
我看了一遍,我用的時候挺好的,幫你up!!
wyp0623 2004-07-01
  • 打赏
  • 举报
回复
结贴吧
孟子E章 2004-06-30
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50
wyp0623 2004-06-30
  • 打赏
  • 举报
回复
有谁帮我指出错误呢

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧