JDev

Code, .NETFebruary 12, 2009 8:18 pm

This solution was found on http://razvan.cosma.name/weblog/index.php?entry=entry090116-161656

private void ExportToExcel(string strFileName, GridView gv)
        {
            Response.ClearContent();
            Response.ContentType = "application/excel";
            Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
            Response.Charset = "";         
            Response.ContentEncoding = System.Text.Encoding.Unicode;
            Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
            this.EnableViewState = false;
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
            Response.Write(sw.ToString());    
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

 

 

 

.NET, ExcelJanuary 6, 2009 9:31 pm

Here is a discussion of the captioned issue with a solution posted at the end of the page, pointing to a third-party solution.

Code, .NETNovember 7, 2008 9:25 pm

 

I use this function found on the stackoverflow site to check whether a string is a number:

return System.Text.RegularExpressions.Regex.IsMatch
         (TextValue, @"^-?\d+([\.]{1}\d*)?$");

 It recognizes integers and decimals. However, it fails on comma separators.

 

More tips at http://c-sharpe.blogspot.com/

Code, javascript, .NETJune 25, 2008 1:36 pm

When you use href=’#’ and provide a JavaScript function for the onclick event, the browser always jumps to the top of the page after executing the JavaScript function. The simple way to avoid the jumping effect is to include a ‘return false’ statement after the call to the JavaScript function. Example:

<a href=’#’ onclick=’fnClick(this); return false;’>Do something </a> 

If you use .NET 1.1, you can set "Smartnavigation=true" in Document properties.