Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

I have just written a new article "Extensive Study of the GridView Export to Excel" in which I talked about different ways that you can use to export the GridView to excel. You can check out the article at the following link.

http://gridviewguy.com/ArticleDetails.aspx?articleID=197

 

powered by IMHO 1.3

Posted on Sunday, August 13, 2006 7:05 PM | Back to top


Comments on this post: Extensive Study of the GridView Export to Excel

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
Thanks for the article. I am trying your code but I get this error message: RegisterForEventValidation can only be called during Render();

I am basically using the same code (I also tried using the ValidateRequest="false" but it still doesnt work).

The only difference is that my gridview is populated not by a DataSet but by a generic List collection of objects. Could that be causing the problem?
Left by Victor A. on Aug 24, 2006 11:56 AM

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
Hi,

Are you overriding the VerfiyRenderingInServerForm method.

public override void VerifyRenderingInServerForm(Control control)
{

}

PLUS: You can disable the EventValidation in the page directive.

EnableEventValidation="false"

Hope that helps!
Azam



Left by AzamSharp on Aug 24, 2006 12:01 PM

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
Thanks Azam!

Adding EnableEventValidation="false" to the Page Directive fixed the problem.
Left by Victor A. on Aug 24, 2006 12:12 PM

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
Azam,

I am getting unknow error trying to do this in aspnet2.0, i have tried all of items you mentioned
1. rendering issue
2. enableeventvalidation=false in page

below the exact code, i tried variations in VB.net disable code, I am using Mater pages and content panel

Please let me know

Neel

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Try
' DisableControls1(gdvCategories)
' Response.Clear()
' Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
' Response.Charset = ""
' ' If you want the option to open the Excel file without saving than
' ' comment out the line below
' Response.Cache.SetCacheability(HttpCacheability.NoCache)
' Response.ContentType = "application/vnd.xls"

' Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter
' Dim htmlWrite As System.Web.UI.HtmlTextWriter = New Html32TextWriter(stringWriter)
' gdvCategories.RenderControl(htmlWrite)
' Response.Write(stringWriter.ToString())
' Response.End()
'Catch ex As Exception
' Dim ertxt As String = ex.StackTrace
'End Try

End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

' Confirms that an HtmlForm control is rendered for the specified
'ASP.NET server control at run time.
End Sub 'VerifyRenderingInServerForm

Private Sub DisableControls1(ByVal gdvCategories As Control)
'Dim l As Literal = New Literal()
'Dim i As Integer = Nothing

'For i = 0 To gdvCategories.Controls.Count - 1 Step i + 1
' If TypeOf (gdvCategories.Controls(i)) Is LinkButton Then
' Dim lnkButtton As LinkButton
' lnkButtton = CType(gdvCategories.FindControl("LinkButton1"), LinkButton)
' If lnkButtton IsNot Nothing Then
' l.Text = lnkButtton.CommandName.ToString
' End If
' gdvCategories.Controls.Remove(gdvCategories.Controls(i))
' gdvCategories.Controls.AddAt(i, l)
' End If
' If gdvCategories.Controls(i).HasControls() Then
' DisableControls1(gdvCategories.Controls(i))
' End If
'Next
End Sub
Left by Neel on Aug 25, 2006 7:05 AM

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
Hi,

That was a nice article posted by you. It is really helpful. I am wondering if it is possible to select only few columns or rows from datagrid and export them to excel. Any ideas?

Thank you,
Anu
Left by Anu on Sep 11, 2006 1:13 PM

# re: Extensive Study of the GridView Export to Excel
Requesting Gravatar...
It is very helpfull, i have one more problem , when i m exporting from gridview to excel , euro symbol is getting grabled ( not coming properly )
Left by ruchir on Feb 17, 2008 10:43 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net