Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Asp.net Currency Exchange Rate via RSS

0.00/5 (No votes)
20 Jun 2007 1  
This articles is to explain the use on live XML for displaying data. I have used Exchange Rates from currencysource.com to show one of many use of this technique. I have used bit of comments to explain how this code is working.

Introduction

This code uses an RSS feed offering the latest currency exchange rates and pulls data from it when the user clicks a Fetch button. The user is able to choose a currency for which to fetch exhange rates on. This code is useful since it fetches up-to-date details on currency exchange rates - something which is ever more expected of systems that deal with commercial applications.

Background

This code uses ASP .Net 2.0, C# 2.0 and also demonstrates the usefulness of Prototype.js (a third party Javascript framework).

Using the code

The codebehind code is given as reference and followed by html code

//using System;


//using System.Data;


//using System.Configuration;


//using System.Collections;


//using System.Web;


//using System.Web.Security;


//using System.Web.UI;


//using System.Web.UI.WebControls;


//using System.Web.UI.WebControls.WebParts;


//using System.Web.UI.HtmlControls;


//using System.Xml;


//public partial class Modules_LiveExchangeRates : System.Web.UI.Page


//{


// protected void Page_Load(object sender, EventArgs e)


// {


// if (!Page.IsPostBack)


// {




// }


// }


// private void PopulateGrid(string vstrURL)


// {


// if (lstExchange.Items.Count > 0)


// {


// lstExchange.Items.Clear();


// }


// XmlDocument objDoc = new XmlDocument();


// objDoc.Load(vstrURL);


// XmlNodeList objNL;




// if (null != objDoc)


// {


// objNL = objDoc.SelectNodes("rss/channel/item");


// if (null != objNL)


// {


// foreach (XmlNode XNode in objNL)


// {


// lstExchange.Items.Add(XNode.ChildNodes[0].InnerText);


// } 


// }


// }


// }


// protected void btnFetchValue_Click(object sender, EventArgs e)


// {


// PopulateGrid(txtURL.Text.Trim());


// }


//}


 

 

 

//----------- HTML Code


 //<html xmlns="http://www.w3.org/1999/xhtml" >

//<head id="Head1" runat="server">

//    <title>Page</title>

//    <link href="../Styles/StyleSheet.css" rel="stylesheet" type="text/css" />

//    <script type="text/javascript" src="../scripts/prototype.js"></script>


//    <script type="text/javascript"> 

//    <!--

//function Rvalue() {

//  document.getElementById("rssText").innerHTML = "Copy URL into RSS Application...<br>" + document.frmPage["rss"].value;

//  $("txtURL").value=$("rss").value;

//}

//--> </script> <style type="text/css"> <!--

//.graybox {

//border: solid 1px gray;

//}


//#graybox {

//border: solid 1px gray;

//}


//.rssText {  

//    font-family: Arial, Helvetica, sans-serif; font-size: 0.8em; color: #333399;

//}


//#smlink {

//font-size: .6em;

//color: #dedede;

//font-style: normal;

//font-family: Arial, Helvetica, sans-serif;

//}


//#smlink a:link,#smlink a:visited{

//color: #7e7e7e; /*Was #dedede.*/

//text-decoration: none; }


//#smlink a:hover {

//color: #7e7e7e; 

//text-decoration: underline}

//--> </style>


//</head>

//<body>

//    <form id="frmPage" runat="server">

//    <table id="tblMain" style="width:100%" class="tablebdr1">

//    <tr>

//    <td style="height:20px" class="textorg">Live Exchage Rates</td>


//    </tr>

//    <tr>

//    <td style="height:20px"></td>


//    </tr>


//    <tr>

//    <td>

// <table border="0" cellspacing="2" cellpadding="2" id="graybox" style="width: 273px; height: 74px"> 

// <tr> <td class="textorg"><div align="center">

//    Currency Exchange Rates via <b>RSS</b></div></td></tr><tr><td>

//<select name="rss" onchange="javascript:Rvalue()">

//    <option value="0" selected="selected">Select a Currency...</option>

//    <option value="http://currencysource.com/RSS/ARS.xml">Argentine Peso</option>

//    <option value="http://currencysource.com/RSS/AUD.xml">Australian Dollar</option>

//    <option value="http://currencysource.com/RSS/BHD.xml">Bahrain Dinar</option>

//    <option value="http://currencysource.com/RSS/BWP.xml">Botswana Pula</option>

//    <option value="http://currencysource.com/RSS/BRL.xml">Brazilian Real</option>

//    <option value="http://currencysource.com/RSS/BND.xml">Brunei Dollar</option>

//    <option value="http://currencysource.com/RSS/CAD.xml">Canadian Dollar</option>

//    <option value="http://currencysource.com/RSS/CLP.xml">Chilian Peso</option>

//    <option value="http://currencysource.com/RSS/CNY.xml">Chinese Yuan</option>

//    <option value="http://currencysource.com/RSS/COP.xml">Colombian Peso</option>

//    <option value="http://currencysource.com/RSS/CYP.xml">Cyprus Pound</option>

//    <option value="http://currencysource.com/RSS/CZK.xml">Czech Koruna</option>

//    <option value="http://currencysource.com/RSS/DKK.xml">Danish Krone</option>

//    <option value="http://currencysource.com/RSS/EUR.xml">Euro</option>

//    <option value="http://currencysource.com/RSS/HUF.xml">Hungarian Forint</option>

//    <option value="http://currencysource.com/RSS/ISK.xml">Icelandic Krona</option>

//    <option value="http://currencysource.com/RSS/INR.xml">Indian Rupee</option>

//    <option value="http://currencysource.com/RSS/IDR.xml">Indonesian Rupiah</option>

//    <option value="http://currencysource.com/RSS/IRR.xml">Iranian Rial</option>

//    <option value="http://currencysource.com/RSS/ILS.xml">Israeli New Sheqel</option>

//    <option value="http://currencysource.com/RSS/JPY.xml">Japanese Yen</option>

//    <option value="http://currencysource.com/RSS/KRW.xml">Korean Won</option>

//    <option value="http://currencysource.com/RSS/KWD.xml">Kuwaiti Dinar</option>

//    <option value="http://currencysource.com/RSS/LYD.xml">Libyan Dinar</option>

//    <option value="http://currencysource.com/RSS/MYR.xml">Malaysian Ringgit</option>

//    <option value="http://currencysource.com/RSS/MTL.xml">Maltese Lira</option>

//    <option value="http://currencysource.com/RSS/MUR.xml">Mauritian Rupee</option>

//    <option value="http://currencysource.com/RSS/MXN.xml">Mexican Peso</option>

//    <option value="http://currencysource.com/RSS/NPR.xml">Nepalese Rupee</option>

//    <option value="http://currencysource.com/RSS/NZD.xml">New Zealand Dollar</option>

//    <option value="http://currencysource.com/RSS/NOK.xml">Norwegian Krone</option>

//    <option value="http://currencysource.com/RSS/OMR.xml">Omani Rial</option>

//    <option value="http://currencysource.com/RSS/PKR.xml">Pakistan Rupee</option>

//    <option value="http://currencysource.com/RSS/PLN.xml">Polish Zloty</option>

//    <option value="http://currencysource.com/RSS/GBP.xml">Pound Sterling</option>

//    <option value="http://currencysource.com/RSS/QAR.xml">Qatar Riyal</option>

//    <option value="http://currencysource.com/RSS/SAR.xml">Saudi Arabian Riyal</option>

//    <option value="http://currencysource.com/RSS/SGD.xml">Singapore Dollar</option>

//    <option value="http://currencysource.com/RSS/SIT.xml">Slovenian Tolar</option>

//    <option value="http://currencysource.com/RSS/ZAR.xml">South African Rand</option>

//    <option value="http://currencysource.com/RSS/LKR.xml">Sri Lanka Rupee</option>

//    <option value="http://currencysource.com/RSS/SEK.xml">Swedish Krona</option>

//    <option value="http://currencysource.com/RSS/SEK.xml">Swiss Franc</option>

//    <option value="http://currencysource.com/RSS/THB.xml">Thai Baht</option>

//    <option value="http://currencysource.com/RSS/TTD.xml">Trinidad & Tobago Dollar</option>

//    <option value="http://currencysource.com/RSS/AED.xml">U.A.E. Dirham</option>

//    <option value="http://currencysource.com/RSS/USD.xml">U.S. Dollar</option>

//    <option value="http://currencysource.com/RSS/VEB.xml">Venezuelan Bolivar</option>

//</select>

//</td>

//    </tr>

//     <tr style="display:none">

// <td>

//     <div align="left">

//     </div>

//     <div id="rssText" align="left" class="textorg">


//// URL:

//     </div>

//     <asp:TextBox ID="txtURL" runat="server" Text=""></asp:TextBox>

// </td>

//     </tr>


//  </table>

//  <!-- That's it! Your site visitors now have access to continuously updated Currency Exchange Rates via RSS! --> 

//<asp:Button ID="btnFetchValue" runat="server" Text="Fetch Value" OnClick="btnFetchValue_Click" /></td>

//    </tr>


//     <tr>

//    <td>

//    <asp:ListBox ID="lstExchange" runat="server" Width="363px" Height="456px"></asp:ListBox>

//    </td>



//    </tr>



//    </table>

//    </form>

//</body>

//</html>



 

 

Remember to set the Language of your code snippet using the Language dropdown.

Use the "var" button to to wrap Variable or class names in <code> tags like this.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here