Saturday, October 13, 2012

How to add ASP.NET 4.0 as Application Pool on IIS 7, Windows 7

  1. Open your command prompt (Windows + R) and type cmd and press ENTER
    You may need to start this as an administrator if you have UAC enabled.
    To do so, locate the exe (usually you can start typing with Start Menu open), right click and select "Run as Administrator"
  2. Type cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\ and press ENTER.
  3. Type aspnet_regiis.exe -ir and press ENTER again.

Saturday, June 30, 2012

RadGrid - Export to Excel with Custom Currency Format

A couple days ago, I had a requirement from client that is they want to export to excel from RadGrid with the currency format is "$ xxx.xx USD" (may be it's negative value), moreover, in that excel file, they can calculate their fields. After googling on 2-day I had no result although I tried to ask the question on telerik forum at here and also stackoverflow.
Luckily, based on some suggestions on both 2 site, I solved this problem (phew, God bless me)

Below is all steps to get it (I assumed we can format "$ xxx.xx USD" on grid)

Step 1:
Register the ExcelExportCellFormatting event for grid

protected void grid_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
     var item = e.Cell.Parent as GridDataItem;
     var hdfCurrency = item.FindControl("hdfCurrency") as HiddenField;
     var format = FormatCurrencyWhenExportToExcel(hdfCurrency.Value);
     switch (e.FormattedColumn.UniqueName)
     {
          case "TotalPrice":
              var hdfTotalPrice = item.FindControl("hdfTotalPrice") as HiddenField;
              // Assumption the hdfTotalPrice.Value = "25.00" or "-25.00";
 
              e.Cell.Text = hdfTotalPrice.Value;
              e.Cell.Style["mso-number-format"] = format;
              break;
     }
}


Step 2:
Write the FormatCurrencyWhenExportToExcel function

public static string FormatCurrencyWhenExportToExcel(string currency)
{
       var regionInfo = new System.Globalization.RegionInfo(Globals.GetCurrencyCulture(currency).Name);
       var format = @"\0022" + regionInfo.CurrencySymbol + @"\0022\#\,\#\#0\.00\ \0022" + regionInfo.ISOCurrencySymbol + @"\0022";
       return format;
}
 
That's all.
Enjoy your code.
 
We can reference these sites: 
http://niallodoherty.com/post.cfm/basic-html-to-excel-formatting
http://agoric.com/sources/software/htmltoExcel
http://cosicimiento.blogspot.com/2008/11/styling-excel-cells-with-mso-number.html
http://www.telerik.com/help/aspnet-ajax/grid-html-export.html
 

Tuesday, March 13, 2012

Searching special character (e.g. %,_) with .NET and Stored Procedure

Today, I spent 2 hours to searching the way to search with "%,_" characters. When my QC fill these characters on search textbox, it has shown all items. How a stupid I am!! :D
Finally, I found the way to fix it. It's quite simple. Below is the steps
Assumption, your text search is "%" (I named it is searchText variable)
          searchText = searchText .Replace("%","[%]"); //same with "_" character
It works right way....
For more information you can see "WildCard Characters" section in this page
LIKE '5[%]' = 5%
LIKE '[_]n' = _n
LIKE '[a-cdf]' = a, b, c, d, or f
LIKE '[-acdf]' = -, a, c, d, or f
LIKE '[ [ ]' = [
LIKE ']' = ]
LIKE 'abc[_]d%' = abc_d and abc_de
LIKE 'abc[def]' = abcd, abce, and abcf