Export datagrid(with allowsorting) to Excel

  • Thread starter Cowboy \(Gregory A. Beamer\)
  • Start date
C

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.


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.
 
A

Alex B

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

=?gb2312?B?RXJzaW4gR2VuP3SouXJr?=

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


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.
 
E

Eric

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top