MVC 3- Grid. Export Data into Excel and PDF - asp.net-mvc-3

I am using MVC3 Web Grid. I need to export the data into excel 2003 and Higher and to PDF.
I have two button under the grid, When I click on the first button, I should be able to export to excel 2003 and save the data.
When I click on the second button, I should be able to export in to PDF format.
Using Grid View in Webforms, I have done that, but using MVC3, I have not done that.
Any directions please? Is there anything that comes up with in MVC3 framework for export functionality.
Thank you

Is there anything that comes up with in MVC3 framework for export functionality.
No nothing. To export to Excel you could use CSV and use a controller action which will fetch the data from wherever you fetched it initially to display on the grid and return a File content with CSV:
public ActionResult ExportToExcel()
{
byte[] csvData = ... fetch the data from your repository and convert to CSV
return File(csvData, "text/csv", "data.csv");
}
To export to PDF, well, nothing built-in .NET. You will need a third party library. Personally I use iTextSharp to achieve this functionality.

You can check here for an easy way to export to CSV. You don't have to worry about converting your data to CSV, this will do it.

Related

Dynamics CRM - Custom development

I'm completely new to the Dynamics CRM environment.
Within our current implementation, there is a grid which displays a list of current sales opportunities. Within this grid, there is a column for the user which is a link to another part of Dynamics. We want to instead be able to open a new window to another system. How can I customize how that link gets rendered out so that the client "onclick" function can link to a javascript function which will open a new window with the URL we need?
Please see attached:
Snapshot of Dynamics grid
Im afraid that this is not possible with supported customization.
My understanding is that you will keep URL to external system on entity and you would like to be able to open with single click from grid displaying this record?
However, Im not sure if you add this fields as single line of text with format option URL won`t work as expected. If this does not work, you would need a custom grid to display this data.
You can store url in text field with format URL, click on such field will open link in new window/tab.

Export view to Excel or PDF using mvc core and razor

We are trying to export both partial and complete views to Excel. The code almost produce what we want but we have a problem that we must get fixed.
The file doesn't have the excel extension and we have to choose a program to open the file, that behavior is not wanted. :)
Below is an example on how we set the response header and return a partial view with the model we want to put on excel spreadsheet (from within a controller/action).
Response.Headers.Add("Content-Type", "application/ms-excel");
return PartialView("~/views/customer/_PlantListPartial.cshtml", plants);
How can we achieve what we want and is it even possible? And yes, we run asp.net core on .net framework, not .net core framework.
Add one more header:
Content-Disposition: attachment; filename="filename.xls"

Kendo ui datagrid

I am just trying to use keno ui into my project. But Kendo is new to me. So I am not sure how to proper use it. Some of the widgets like dialog window, datepicker, timepicker etc. are easy to use but I am having problem with datagird. Could anybody let me know how can we use datagrid widget server databound and xml as datatype. Please give me little bit give me an example. If possible. Let me know how xml file will look. How can we get page number, number of rows on the server side. I am using asp.net with c# as server side language.
Is there a reason why you want to bind to an xml file? Generally speaking you should be using JSON for the dataSource. For an example of using an xml datasource have you looked at this:
Binding to xml DataSource
If you haven't used these before and have access to the MVC Wrappers then I would suggest looking at this demo as a good starting place for the Grid:
Kendo Grid bound to local data
Kendo Grid bound to remote data
If you use the demo from the first example and apply it to the "local data" example this should get you going. If you get stuck please provide some code showing what you have tried and any issues you are faced with.

Generate PDF from view using iTextSharp

My requirement is to have a button in my view and clicking on that should generate a PDF report from that view. (Should avoid making another trip to database to get data for the PDF report).
I decided to use iTextSharp. Could some body please post some examples or direct me to a proper article?
I answered something similar on this link.
You will need to sort out the caching of the data from the DB though, this version just queried it again.
How to make a pdf report of a particular view in mvc3

Image button inside a Data table

I'm facing a scenario that i need to add image button inside a datatable. Is it possible to add an image button control inside a datatable.
I'm using Framework 3.5 and C# language.
Thanks In Advance!
Regards,
Ranga
I think you are trying to work with a user interface control like a DataGrid or DataGridView. DataTable is an ADO.NET class for holding data from a database. It doesn't present data in a user interface, so adding an image button maes no sense.
I presume you're working with a grid of some sort, but in order to get a sensible answer you need to tell us which one. Is your user interface WPF, Windows Forms, or ASP.NET? Specifically, which grid class are you trying to use?

Resources