In This coding we r doing the currency conversion The Rsult is displaying lick this
144 USD = NaN INR
Whay hear NAN(Not a number) is displaying
plz help me and what is the changes and how to do that plz tell me
In web.config I am using this Rss feed:
<add key="CurrencyLink" value="http://currencysource.com/RSS/USD.xml"/>
In JavaScript :
//This particular function retreives and displays the currency results of the usered selected input
function DisplayCurrencyValue(link,currency)
{
var str,objXMLNode,objXMLDoc,objEmployee,strHTML;;
var stri=AJAXUtilities.GetCurrencyValue(link,currency);
str = stri.value;
var result= parseFloat(str);
var value=parseFloat(document.getElementById("txtConvert").value)
if(isNaN(value))
{
value=1;
document.getElementById("txtConvert").value=1;
}
var city=document.getElementById("ddlTo");
var url=document.getElementById("ddlFrom");
var path=url.options[url.selectedIndex].text;
var pathCurr=url.options[url.selectedIndex].value;
var
currencyAbr=pathCurr.substring(pathCurr.length-7,pathCurr.length-7+3);
var curr=city.options[city.selectedIndex].value;
Result=result*value;
var str=value+"
"+currencyAbr+" = "+ Result +" "+curr;
document.getElementById("lblConverResult").value=str;
// document.getElementById("txtConvert").focus();
}
//This particular function gets the user selected input and invokes the fucnction which retreives the details
function DisplayCurrencyResult()
{
var city=document.getElementById("ddlTo");
var url=document.getElementById("ddlFrom");
var path=url.options[url.selectedIndex].value;
var curr=city.options[city.selectedIndex].value;
DisplayCurrencyValue(path,curr);
}
In AJAX coding :
//This particular method returns xml document with currency details
[Ajax.AjaxMethod()]
public XmlDocument GetCurrencyDetails()
{
DataSet ds3 = new DataSet();
string currencyUrl =
ConfigurationSettings.AppSettings["CurrencyLink"].ToString();
ds3.ReadXml(currencyUrl, XmlReadMode.Auto);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ds3.GetXml());
return xmlDoc;
}
//This particular method returns the respective value of the currency as a string
[Ajax.AjaxMethod()]
public string GetCurrencyValue(string url, string currency)
{
DataSet ds3 = new DataSet();
ds3.ReadXml(url,
XmlReadMode.Auto);
DataTable table = ds3.Tables[3];
string curren = currency.Trim();
string title = "";
string rate = "";
string exchange = "";
string outPut = "";
foreach (DataRow row in table.Rows)
{
title = row["title"].ToString();
int endPoint = title.IndexOf("=");
int startPoint = title.IndexOf("(");
int ePoint = title.IndexOf("(");
rate = title.Substring(endPoint + 2);
exchange = (rate.Substring(0, 3));
if (exchange.Equals(curren))
{
outPut = rate.Substring(5, (rate.Length - 1) - 5);
}
rate = title.Substring(startPoint + 1, 3);
}
decimal tr = Convert.ToDecimal(rate.Substring(0, rate.Length - 1));
tr = tr * 100;
//XmlDocument xmlDoc = new XmlDocument();
return outPut;
}
In Index.aspx.cs
//Binds the Currency detatils to the dropdownlist
public void BindCurrency()
{
CurrencyDetails newCurrency = new CurrencyDetails();
CurrencyDetailsCollection newCurrencyColl = new CurrencyDetailsCollection();
newCurrencyColl = newCurrency.getAllCurrencies();
ddlFrom.Items.Clear();
ddlTo.Items.Clear();
if (newCurrencyColl.Count > 0)
{
ddlFrom.DataSource = newCurrencyColl;
ddlFrom.DataTextField = "CurrencyDesc";
ddlFrom.DataValueField = "CurrencyURL";
ddlFrom.DataBind();
ddlTo.DataSource = newCurrencyColl;
ddlTo.DataTextField = "CurrencyDesc";
ddlTo.DataValueField = "currency_abbr";
ddlTo.DataBind();
ddlFrom.SelectedIndex = 45;
ddlTo.SelectedIndex = 45;
}
}
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).