Export datagrid(with allowsorting) to Excel

Discussion in 'ASP .Net' started by Cowboy \(Gregory A. Beamer\), Jun 25, 2003.

  1. 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" <> wrote in message
    news:...
    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\), Jun 25, 2003
    #1
    1. Advertising

  2. Cowboy \(Gregory A. Beamer\)

    George Durzi Guest

    what he said, sort on the data layer

    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:...
    > 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, Jun 25, 2003
    #2
    1. Advertising

  3. Cowboy \(Gregory A. Beamer\)

    CJM Guest

    He can probably tell you how to set your clock...
    CJM, Jun 26, 2003
    #3
  4. Cowboy \(Gregory A. Beamer\)

    Alex B Guest

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

    "Eric" <> wrote in message
    news:%...
    > Would you like to tell me how to do?
    > Thanks.
    >
    > "Cowboy (Gregory A. Beamer)" <>

    дÈëÏûÏ¢
    > ÐÂÎÅ:...
    > > 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" <> wrote in message
    > > news:...
    > > 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, Jun 26, 2003
    #4
  5. 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" <> wrote in message news:...
    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.
    =?gb2312?B?RXJzaW4gR2VuP3SouXJr?=, Jun 27, 2003
    #5
  6. Cowboy \(Gregory A. Beamer\)

    Eric Guest

    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, Jul 3, 2003
    #6
  7. Cowboy \(Gregory A. Beamer\)

    Eric Guest

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

    "Cowboy (Gregory A. Beamer)" <> дÈëÏûÏ¢
    ÐÂÎÅ:...
    > 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" <> wrote in message
    > news:...
    > 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, Jul 4, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2g=?=

    DataGrid.AllowSorting and CssClass

    =?Utf-8?B?a2g=?=, Aug 2, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,541
    Joe Fallon
    Aug 3, 2004
  2. Samuel Shulman

    AllowSorting dosn't work

    Samuel Shulman, Jun 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,638
    Samuel Shulman
    Jun 13, 2006
  3. Julia B
    Replies:
    0
    Views:
    766
    Julia B
    Nov 3, 2009
  4. tony010409020622@

    AllowSorting = True, BUT Web DataGrid Wont Sort

    tony010409020622@, Sep 29, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    174
    Scott M.
    Sep 29, 2005
  5. Dan Dorey via .NET 247

    dynamic datagrids and allowsorting

    Dan Dorey via .NET 247, Aug 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    105
    Dan Dorey via .NET 247
    Aug 4, 2004
Loading...

Share This Page