Export ListView to Excel

by jrose 8/20/2010 10:02:00 AM

All results that I came across when performing a search for export listview to excel were related to instances of Windows.Forms.ListView and not System.Web.UI.WebControls.ListView.


Attached are the two functions necessary to export instances of System.Web.UI.WebControls.ListView to Excel.

public override void VerifyRenderingInServerForm(Control control) { }

protected void btnExport_Click(object sender, EventArgs e)
    Response.Buffer = true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "";
    this.EnableViewState = false;
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

Tags: , , ,

.NET | ASP.NET AJAX | Excel Programming

Visual Studio 2008: Close Start Page on Solution Load

by jrose 7/22/2010 5:24:00 AM

Visual Studio 2010 provides a check box at the bottom of the start page that allows the option to automatically close the start page when a solution is loaded.

However, Visual Studio 2008 does not make it quite as easy.  One solution is to open the Macro Editor (Alt + F11) and add the following code inside of MyMacros -> EnvironmentEvents:

Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
    If DTE.ActiveWindow.Caption = "Start Page" Then
    End If
End Sub

Tags: , ,

Windows Server 2003, WCF Services, and Windows Update

by jrose 6/28/2010 8:17:00 AM

Lately, Windows Update has been breaking a WCF service that we have running on a machine running Windows Server 2003.  I traced the problem to KB982168.  The temporary fix is to run 'c:\Hotfixes\NDP30SP2-KB982168-x86.exe /uninstall'.

However, if Automatic Updates is configured to automatically install new updates every night at midnight, for example, the problem will re-occur each morning.  In order to just disable this specific update, I went to http://www.update.microsoft.com/, Custom, expanded the + box next to KB982168, and selected Don't show this update again.


ReportViewer Control: Fit to Page

by jrose 5/11/2010 9:09:00 AM

The ReportViewer control's export functionality can be temperamental.


In order to guarantee that the exported file will not be wider than a page, use the following formula:

Body.Size.Width + Report.Margins.Left + Report.Margins.Right <= Report.PageSize.Width


(since, in our case, InteractiveSize and PageSize are the same, this means InteractiveSize can be substituted in PageSize above)

Tags: , , ,


Handle Enter key like the Tab key

by jrose 5/7/2010 9:57:00 AM

To allow ease of use for users that aren't accustomed to using the Tab key to switch between HTML elements and would prefer to use the Enter instead, simply add a OnKeyDown event handler to the element that changes a key code of 13 [Enter's value] to 9 [Tab's value].


For example:

<input type="text" onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }" id="text1">

<input type="text" id="text2">


After entering text into the text1 element, the user is allowed to press Enter [or Tab] to navigate to the text2 element.

Tags: , , , , , ,


File Name Underscores: Internet Explorer vs. Firefox

by jrose 5/7/2010 9:09:00 AM

Internet Explorer and Firefox handle saving documents with file names containing underscores differently.  IE will, by default, save the document with the desired file name containing underscores.  However, Firefox will instead replace all of the underscores with '%5f'.  This can be avoided by wrapping the desired file name in Uri.UnescapeDataString().


For example, with the ReportViewer class:

[ReportViewer instance].LocalReport.DisplayName = Uri.UnescapeDataString("File_name.ext")


The resulting document will, by default, be saved as File_name.ext from IE and as File name.ext from Firefox

Tags: , , , ,


Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail


<<  September 2022  >>

View posts in large calendar

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2022

Sign in