如何将动态创建的控件导出为ex​​cel? [英] How to export the dynamically created controls to excel?

查看:85
本文介绍了如何将动态创建的控件导出为ex​​cel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,即时通讯使用带有内容页面的母版页,在其中一个内容页面中,我创建了动态控件,如文本框,vb代码文件中的复选框,使其成为表结构,最后将其全部绑定到我在设计页面中指​​定的标签。



现在我必须将该标签导出到Excel,当我尝试导出时,它会导出整个页面内容我也从主页使用但没有看到tat标签内容。我只想单独导出该标签。



任何人都面对并解决了这个问题?



感谢Advance Frnds !!

In my web application, i m using a master page with content pages, in one of that content page i have created dynamic controls such as text boxes,check boxes in vb code file make it as a table structure and finally bind it all to the label which i assigned in the design page.

Now i have to export that label to Excel, when i try to export, it exports with the entire page content which i also used from master page but not seen tat label content. I only want to export that label alone.

Anyone faced and solved this??

Thanks in Advance Frnds!!

推荐答案



试试这个



< asp:Button ID =btnexcel Text =Export to excelrunat =server/>



< table id =excelrunat =serverwidth =100% >

< asp:标签样式=宽度:100%; ID =Label1runat =serverText =Export to Excel>











受保护的子btnexcel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理btnexcel.Click

exportToExcel(excel)

End Sub

Public Overrides Sub Validate()

返回

End Sub

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)

返回

结束子





Public Sub exportToExcel(ByVal objDataGrid As Control)

'// objDataGrid.AllowPaging = false;

'// objDataGrid.DataBind();



回复.Clear()

Response.Buffer = True

Response.ContentType =application / vnd.ms-excel

Response.Charset =

Me.EnableViewState = Fals e $>


Dim oStringWriter As New System.IO.StringWriter()

Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)



objDataGrid.RenderControl(oHtmlTextWriter)



Response.Write(oStringWriter.ToString())



Response.End()



End Sub
Hi,
Try this

<asp:Button ID="btnexcel" Text="Export to excel" runat="server" />

<table id="excel" runat="server" width="100%">
<asp:Label style="width:100%;" ID="Label1" runat="server" Text="Export To Excel" >





Protected Sub btnexcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnexcel.Click
exportToExcel(excel)
End Sub
Public Overrides Sub Validate()
Return
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)
Return
End Sub


Public Sub exportToExcel(ByVal objDataGrid As Control)
' // objDataGrid.AllowPaging = false;
' // objDataGrid.DataBind();

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False

Dim oStringWriter As New System.IO.StringWriter()
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

objDataGrid.RenderControl(oHtmlTextWriter)

Response.Write(oStringWriter.ToString())

Response.End()

End Sub


这篇关于如何将动态创建的控件导出为ex​​cel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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