Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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!!
Posted
Comments
Maciej Los 5-Dec-14 2:03am    
You can't export controls, but the data holded by these controls.
What have you done till now?
Where are you stuck?

1 solution

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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900