Since, most of the applications these days require a feature to export the GridView to excel so I decided to make it into a custom control. The control was actually a simple user control which was converted to the custom control using the Visual Studio.NET 2005 Publish and ASP.NET build features. The control is in the form of the dll so you can simply download it and reference the assembly in your application. Once, you have the reference to the assembly you can simply use the control as following:

As, you can see that the properties of the ExportButton are quite simple. The GridViewID denotes the ID of the GridView which you are trying to export and the FileName attribute denotes the name of the exported file. You can also use the ExportButton control with the master pages all you need to find is the correct ID of the GridView and you are good to go. Here is a simple example that shows the GridView which is contained inside the ContentPlaceHolder.

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Value cannot be null.Parameter name: GridViewID Invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.