gridview export to excel stop working after updatepanel added

Last post 04-16-2007 2:14 PM by schwadogg81. 1 replies.

Sort Posts:

  • gridview export to excel stop working after updatepanel added

    04-05-2007, 6:36 AM
    • Loading...
    • giovazza
    • Joined on 04-03-2007, 12:39 PM
    • Posts 3

    I've added an updatepaqnel for my gridview and the export to excel functionality stop working.

    System tell me that gridview must be placed in form tag with runat="server"

    What can I do?

    Please help!

    Thank you

  • Re: gridview export to excel stop working after updatepanel added

    04-16-2007, 2:14 PM
    • Loading...
    • schwadogg81
    • Joined on 04-13-2007, 2:56 PM
    • Posts 3

    well, I was getting the same error and what fixed it for me was setting AllowPaging and AllowSorting to false on the GridView.  If you want to keep these properties intact like I did, then what I did was instatiate another GridView and bindData() to new GridView (it will be a temp copy without paging and sorting allowed).  Then I export the new GridView.  Here is a code sample:

     

    Protected Sub ButtonExportData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonExportData.Click

    Dim stringWrite As New System.IO.StringWriter()

    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

    Dim gridViewExportTable As New GridView

    gridViewExportTable.DataSource =

    Me.AccessDataSourceGetTable

    gridViewExportTable.DataBind()

    Response.Clear()

    Response.Charset =

    ""

    Response.ContentType =

    "application/vnd.ms-excel" ' set the content type

    Response.AddHeader(

    "Content-Disposition", " attachment; filename=MyRentNetGrd_Report.xls")

    Page.EnableViewState =

    False

     

    gridViewExportTable.RenderControl(htmlWrite)

    Response.Write(stringWrite.ToString())

    Response.End()

    End Sub

     

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter