Export datagrid(with allowsorting) to Excel

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Export datagrid(with allowsorting) to Excel

    In this instance, since you know what the user wants when you query the
    data, I would consider sorting the data on the server when you pull the
    data. I am not sure why it bombs (I would have to examine the HTML
    produced), but it is easily solved by sorting on the Data tier and avoiding
    the issue on the Presentation tier.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    Author: ADO.NET and XML: ASP.NET on the Edge

    ************************************************** **************************
    ****
    Think Outside the Box!
    ************************************************** **************************
    ****
    "Eric" <Eric_Zsz@hotmail.com> wrote in message
    news:uEQiEKxODHA.3152@TK2MSFTNGP10.phx.gbl...
    Dear All,

    I want to export datagrid content to a Excel file, the code just like
    below:

    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Me.EnableViewState = False
    Dim tw As New System.IO.StringWriter()
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    gridList.Columns(0).Visible = False
    gridList.Columns(1).SortExpression = ""
    gridList.RenderControl(hw)
    Response.Write(tw.ToString())
    Response.End()

    ....

    If my datagrid Allowsorting=true, then the code run error,but if I
    config the Allowsorting=false, then above code run fine.
    Please help me how to export if my datagrid has the allowsorting
    properity.

    Any help welcomes.

    Best Regards,
    Eric.


    Cowboy \(Gregory A. Beamer\) Guest

  2. Similar Questions and Discussions

    1. DataGrid data Export to Excel
      I know we all have users asking "Can I Export/Import to Excel?". Apparently Excel is the best thing to come along to the user community since large...
    2. Export Datagrid to excel
      Hi, I have written the code to export my datagrid to excel. it is working fine. But i have one issue, when ever i click on export button, it...
    3. Display a Datagrid & Export a Datagrid to Excel
      I have a page displaying a datagrid and the user wants to have two options: 1. Export the current "Displayed" datagrid to Excel 2. Export another...
    4. Export Datagrid data to Excel?
      How can I export data from a grid into Excel? Or from a datatable? I don't have a query I am displaying the schema from a database using a...
    5. DataGrid export to excel
      I've asked this question once before, but am still having problems. When I try to export this grid to excel i get the error message i've seen...
  3. #2

    Default Re: Export datagrid(with allowsorting) to Excel

    what he said, sort on the data layer

    "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netRemuvThis> wrote in
    message news:OduJ3xxODHA.452@TK2MSFTNGP11.phx.gbl...
    > In this instance, since you know what the user wants when you query the
    > data, I would consider sorting the data on the server when you pull the
    > data. I am not sure why it bombs (I would have to examine the HTML
    > produced), but it is easily solved by sorting on the Data tier and
    avoiding
    > the issue on the Presentation tier.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    > Author: ADO.NET and XML: ASP.NET on the Edge
    >
    >
    ************************************************** **************************
    > ****
    > Think Outside the Box!
    >
    ************************************************** **************************
    > ****
    > "Eric" <Eric_Zsz@hotmail.com> wrote in message
    > news:uEQiEKxODHA.3152@TK2MSFTNGP10.phx.gbl...
    > Dear All,
    >
    > I want to export datagrid content to a Excel file, the code just like
    > below:
    >
    > Response.ContentType = "application/vnd.ms-excel"
    > Response.Charset = ""
    > Me.EnableViewState = False
    > Dim tw As New System.IO.StringWriter()
    > Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    > gridList.Columns(0).Visible = False
    > gridList.Columns(1).SortExpression = ""
    > gridList.RenderControl(hw)
    > Response.Write(tw.ToString())
    > Response.End()
    >
    > ...
    >
    > If my datagrid Allowsorting=true, then the code run error,but if I
    > config the Allowsorting=false, then above code run fine.
    > Please help me how to export if my datagrid has the allowsorting
    > properity.
    >
    > Any help welcomes.
    >
    > Best Regards,
    > Eric.
    >
    >

    George Durzi Guest

  4. #3

    Default Re: Export datagrid(with allowsorting) to Excel

    He can probably tell you how to set your clock...


    CJM Guest

  5. #4

    Default Re: Export datagrid(with allowsorting) to Excel

    Here's how... Go to the first message that you post dated. Then from the
    Message menu in OE, choose Block Sender.

    "Eric" <Eric_Zsz@hotmail.com> wrote in message
    news:%23kJBsf3ODHA.1336@TK2MSFTNGP11.phx.gbl...
    > Would you like to tell me how to do?
    > Thanks.
    >
    > "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netRemuvThis>
    дÈëÏûÏ¢
    > ÐÂÎÅ:OduJ3xxODHA.452@TK2MSFTNGP11.phx.gbl...
    > > In this instance, since you know what the user wants when you query the
    > > data, I would consider sorting the data on the server when you pull the
    > > data. I am not sure why it bombs (I would have to examine the HTML
    > > produced), but it is easily solved by sorting on the Data tier and
    > avoiding
    > > the issue on the Presentation tier.
    > >
    > > --
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA
    > > Author: ADO.NET and XML: ASP.NET on the Edge
    > >
    > >
    >
    ************************************************** **************************
    > > ****
    > > Think Outside the Box!
    > >
    >
    ************************************************** **************************
    > > ****
    > > "Eric" <Eric_Zsz@hotmail.com> wrote in message
    > > news:uEQiEKxODHA.3152@TK2MSFTNGP10.phx.gbl...
    > > Dear All,
    > >
    > > I want to export datagrid content to a Excel file, the code just
    like
    > > below:
    > >
    > > Response.ContentType = "application/vnd.ms-excel"
    > > Response.Charset = ""
    > > Me.EnableViewState = False
    > > Dim tw As New System.IO.StringWriter()
    > > Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    > > gridList.Columns(0).Visible = False
    > > gridList.Columns(1).SortExpression = ""
    > > gridList.RenderControl(hw)
    > > Response.Write(tw.ToString())
    > > Response.End()
    > >
    > > ...
    > >
    > > If my datagrid Allowsorting=true, then the code run error,but if I
    > > config the Allowsorting=false, then above code run fine.
    > > Please help me how to export if my datagrid has the allowsorting
    > > properity.
    > >
    > > Any help welcomes.
    > >
    > > Best Regards,
    > > Eric.
    > >
    > >
    >
    >

    Alex B Guest

  6. #5

    Default Re: Export datagrid(with allowsorting) to Excel

    hi eric,

    are you getting some error like 'link item must be placed into form tag with an attribute runat=server" if so then your problem is because of when you use htmltextwriter and render control into it where your grids sorting property set to true then link items generate this error because your htmltextwriter doesn't include form tag.try including some form tag into htmltextwriter or , first disable allowsorting property to false , then export to excel and then rebind your dataset with allowsorting set to true (also this has some side effects where grid losts page numbers. etc)

    regards,
    ersin gen?t¨¹rk


    "Eric" <Eric_Zsz@hotmail.com> wrote in message news:uEQiEKxODHA.3152@TK2MSFTNGP10.phx.gbl...
    Dear All,

    I want to export datagrid content to a Excel file, the code just like below:

    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Me.EnableViewState = False
    Dim tw As New System.IO.StringWriter()
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    gridList.Columns(0).Visible = False
    gridList.Columns(1).SortExpression = ""
    gridList.RenderControl(hw)
    Response.Write(tw.ToString())
    Response.End()

    ...

    If my datagrid Allowsorting=true, then the code run error,but if I config the Allowsorting=false, then above code run fine.
    Please help me how to export if my datagrid has the allowsorting properity.

    Any help welcomes.

    Best Regards,
    Eric.


    Ersin Gen?t¨¹rk Guest

  7. #6

    Default Export datagrid(with allowsorting) to Excel

    Dear All,

    I want to export datagrid content to a Excel file, the code just like below:

    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Me.EnableViewState = False
    Dim tw As New System.IO.StringWriter()
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    gridList.Columns(0).Visible = False
    gridList.Columns(1).SortExpression = ""
    gridList.RenderControl(hw)
    Response.Write(tw.ToString())
    Response.End()

    ....

    If my datagrid Allowsorting=true, then the code run error,but if I config the Allowsorting=false, then above code run fine.
    Please help me how to export if my datagrid has the allowsorting properity.

    Any help welcomes.

    Best Regards,
    Eric.


    Eric Guest

  8. #7

    Default Re: Export datagrid(with allowsorting) to Excel

    Would you like to tell me how to do?
    Thanks.

    "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netRemuvThis> дÈëÏûÏ¢
    ÐÂÎÅ:OduJ3xxODHA.452@TK2MSFTNGP11.phx.gbl...
    > In this instance, since you know what the user wants when you query the
    > data, I would consider sorting the data on the server when you pull the
    > data. I am not sure why it bombs (I would have to examine the HTML
    > produced), but it is easily solved by sorting on the Data tier and
    avoiding
    > the issue on the Presentation tier.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    > Author: ADO.NET and XML: ASP.NET on the Edge
    >
    >
    ************************************************** **************************
    > ****
    > Think Outside the Box!
    >
    ************************************************** **************************
    > ****
    > "Eric" <Eric_Zsz@hotmail.com> wrote in message
    > news:uEQiEKxODHA.3152@TK2MSFTNGP10.phx.gbl...
    > Dear All,
    >
    > I want to export datagrid content to a Excel file, the code just like
    > below:
    >
    > Response.ContentType = "application/vnd.ms-excel"
    > Response.Charset = ""
    > Me.EnableViewState = False
    > Dim tw As New System.IO.StringWriter()
    > Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    > gridList.Columns(0).Visible = False
    > gridList.Columns(1).SortExpression = ""
    > gridList.RenderControl(hw)
    > Response.Write(tw.ToString())
    > Response.End()
    >
    > ...
    >
    > If my datagrid Allowsorting=true, then the code run error,but if I
    > config the Allowsorting=false, then above code run fine.
    > Please help me how to export if my datagrid has the allowsorting
    > properity.
    >
    > Any help welcomes.
    >
    > Best Regards,
    > Eric.
    >
    >

    Eric Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139