|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionMicrosoft has done a wonderful job of creating an extensible framework, especially for ASP.NET, by creating various server controls. This article is about extending ASP.NET BackgroundThere are various ways one can export data using ASP.NET. Usually, it is done by coding a separate page and adding various HTTP headers and responses. (Refer: Microsoft). Like me, most of us believe in reuse. The export functionality can be achieved by reusing the same page for various projects either by passing One Click ExportYou may wonder why I call it ONE CLICK EXPORT, 'because this control doesn't require intermediate page for exporting data'. Just drag the 'ASPX page [Design time]
…
…
<pnwc:ExportButton id="btnExcel" runat="server"
Separator="TAB" Text="Export to Excel"
FileNameToExport="Books.xls" BackColor="#E0E0E0"></pnwc:ExportButton>
….
….
'Code Behind [Run time]
Private Sub Page_Load(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds as dataset=filldataset()
dgBooks.DataSource = ds.Tables("Books")
dgBooks.DataBind()
'Set Export button properties
btnExcel.Dataview = ds.Tables("Books").DefaultView
btnExcel.FileNameToExport = "Books.xls"
btnExcel.ExportType = _
PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.Excel
btnExcel.Separator = _
PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.TAB
End Sub
[Note: The Properties Explained
Demo codeThe source code is provided with the sample project to test out the solution.
How to use the Control in your projectYou may either include the PNWebControls project and reference it in your project, or reference the assembly (PNayak.Web.UI.WebControls.ExportButton.dll). You can also add this control in Visual Studio Toolbox for design time. [Note: This assembly also contains Check out my .NET spot for more to discover. History
|
||||||||||||||||||||||