Asp.net

Currency Converter

1. Add Currency Dropdownlist in Master Page with Currency Code and 

On Page Load Of Master Page:

if (!IsPostBack)
{
if (Session[“currency”] == null)
{
Session[“currency”] = “INR”;
}
else
{
drpdwncurrency.SelectedValue = Session[“currency”].ToString();
}

}

On dropdownlist change event :

Session[“currency”] = drpdwncurrency.SelectedValue;
drpdwncurrency.SelectedValue = Session[“currency”].ToString();
Response.Redirect(Request.Url.ToString());

use a session as selected currency

2.Add Belowe Function For Rate 

public static string Convert(double amount, string fromCurrency, string toCurrency)
{
WebClient web = new WebClient();
Uri uri = new Uri(string.Format(“http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}”, fromCurrency.ToUpper(), toCurrency.ToUpper(), amount));
string url = uri.AbsoluteUri + uri.Fragment;
url = web.DownloadString(url);
Regex regex = new Regex(“rhs: \\\”(\\d*.\\d*)”);
Match match = regex.Match(url);
double rate = System.Convert.ToDouble(match.Groups[1].Value.Replace(“\xA0”, “”));
return rate.ToString(“0”);
}

3.Add Belowe Funtion For Currency Symbol and Use Currency font for currency symbol click Here To download Font

public static string CurrencySymbol(string Currency)
{
if (Currency == “INR”)
{
Currency = ” R”;
}
else
{
Currency = ” S”;
}
return Currency;
}

4. Above Function Add In Class File And use as per your requirement in a page

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.