Creating a Simple ASP.NET Report with Export to Excel
page 2 of 5
by Steven Smith
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 41096/ 63

Getting the Data

I'm assuming that you're able to get back your data from a database somehow if that's your data source.  I'm practicing some separation of concerns even though in this case I'm working in a Web Forms application, which means that my data access lives somewhere else, and within my page I have a ViewModel class that has no external dependencies (it's really just a state bag or Data Transfer Object/DTO) that I'll be using for my data binding.  The ViewModel class includes all of the dynamic data elements my page needs to display, and in this case I've put the ViewModel class inside of my codebehind class, but that's just a matter of convenience in this case, and not necessarily a best practice (particularly if you're going to populate the ViewModel from outside of your codebehind class).

For demo purposes, I'm going to use some hard-coded book data.  These are some books I recommend, by the way.  Here's the code that gives me my data - you can see that each Book object includes the Title, Author name, Price, and URL to purchase the book in question:

 


View Entire Article

User Comments

Title: eeqw   
Name: qwrqwr
Date: 2012-11-01 7:42:16 AM
Comment:
qrqwrqwrqwr
Title: dsf   
Name: sdfsd
Date: 2012-04-26 11:17:52 PM
Comment:
dsdfdgdfgdf
Title: MVC3   
Name: Tony
Date: 2011-06-03 5:22:59 PM
Comment:
Nice article, thank you. I used it with mvc3, it works!
Title: ASP.NET   
Name: 5th edition,
Date: 2011-05-27 10:04:06 AM
Comment:
this new book was delivered..
Title: .net 3.5 version needed   
Name: windy
Date: 2011-05-13 8:27:06 AM
Comment:
do the needful.
Title: hi   
Name: hassan humayun
Date: 2011-05-11 8:32:25 AM
Comment:
nice article , but tell me one thing if the user doest have office installed on his system then what will happen, would it throw an exception.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2022 ASPAlliance.com  |  Page Processed at 2022-06-24 10:30:37 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search