Click here to Skip to main content
Click here to Skip to main content

Asp.net Currency Exchange Rate via RSS

, 20 Jun 2007
Rate this:
Please Sign up or sign in to vote.
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="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" >
//<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="<a href="http://currencysource.com/RSS/ARS.xml%22%3EArgentine">http://currencysource.com/RSS/ARS.xml">Argentine</a> Peso</option>
//    <option value="<a href="http://currencysource.com/RSS/AUD.xml%22%3EAustralian">http://currencysource.com/RSS/AUD.xml">Australian</a> Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/BHD.xml%22%3EBahrain">http://currencysource.com/RSS/BHD.xml">Bahrain</a> Dinar</option>
//    <option value="<a href="http://currencysource.com/RSS/BWP.xml%22%3EBotswana">http://currencysource.com/RSS/BWP.xml">Botswana</a> Pula</option>
//    <option value="<a href="http://currencysource.com/RSS/BRL.xml%22%3EBrazilian">http://currencysource.com/RSS/BRL.xml">Brazilian</a> Real</option>
//    <option value="<a href="http://currencysource.com/RSS/BND.xml%22%3EBrunei">http://currencysource.com/RSS/BND.xml">Brunei</a> Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/CAD.xml%22%3ECanadian">http://currencysource.com/RSS/CAD.xml">Canadian</a> Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/CLP.xml%22%3EChilian">http://currencysource.com/RSS/CLP.xml">Chilian</a> Peso</option>
//    <option value="<a href="http://currencysource.com/RSS/CNY.xml%22%3EChinese">http://currencysource.com/RSS/CNY.xml">Chinese</a> Yuan</option>
//    <option value="<a href="http://currencysource.com/RSS/COP.xml%22%3EColombian">http://currencysource.com/RSS/COP.xml">Colombian</a> Peso</option>
//    <option value="<a href="http://currencysource.com/RSS/CYP.xml%22%3ECyprus">http://currencysource.com/RSS/CYP.xml">Cyprus</a> Pound</option>
//    <option value="<a href="http://currencysource.com/RSS/CZK.xml%22%3ECzech">http://currencysource.com/RSS/CZK.xml">Czech</a> Koruna</option>
//    <option value="<a href="http://currencysource.com/RSS/DKK.xml%22%3EDanish">http://currencysource.com/RSS/DKK.xml">Danish</a> Krone</option>
//    <option value="<a href="http://currencysource.com/RSS/EUR.xml%22%3EEuro%3C/option">http://currencysource.com/RSS/EUR.xml">Euro</option</a>>
//    <option value="<a href="http://currencysource.com/RSS/HUF.xml%22%3EHungarian">http://currencysource.com/RSS/HUF.xml">Hungarian</a> Forint</option>
//    <option value="<a href="http://currencysource.com/RSS/ISK.xml%22%3EIcelandic">http://currencysource.com/RSS/ISK.xml">Icelandic</a> Krona</option>
//    <option value="<a href="http://currencysource.com/RSS/INR.xml%22%3EIndian">http://currencysource.com/RSS/INR.xml">Indian</a> Rupee</option>
//    <option value="<a href="http://currencysource.com/RSS/IDR.xml%22%3EIndonesian">http://currencysource.com/RSS/IDR.xml">Indonesian</a> Rupiah</option>
//    <option value="<a href="http://currencysource.com/RSS/IRR.xml%22%3EIranian">http://currencysource.com/RSS/IRR.xml">Iranian</a> Rial</option>
//    <option value="<a href="http://currencysource.com/RSS/ILS.xml%22%3EIsraeli">http://currencysource.com/RSS/ILS.xml">Israeli</a> New Sheqel</option>
//    <option value="<a href="http://currencysource.com/RSS/JPY.xml%22%3EJapanese">http://currencysource.com/RSS/JPY.xml">Japanese</a> Yen</option>
//    <option value="<a href="http://currencysource.com/RSS/KRW.xml%22%3EKorean">http://currencysource.com/RSS/KRW.xml">Korean</a> Won</option>
//    <option value="<a href="http://currencysource.com/RSS/KWD.xml%22%3EKuwaiti">http://currencysource.com/RSS/KWD.xml">Kuwaiti</a> Dinar</option>
//    <option value="<a href="http://currencysource.com/RSS/LYD.xml%22%3ELibyan">http://currencysource.com/RSS/LYD.xml">Libyan</a> Dinar</option>
//    <option value="<a href="http://currencysource.com/RSS/MYR.xml%22%3EMalaysian">http://currencysource.com/RSS/MYR.xml">Malaysian</a> Ringgit</option>
//    <option value="<a href="http://currencysource.com/RSS/MTL.xml%22%3EMaltese">http://currencysource.com/RSS/MTL.xml">Maltese</a> Lira</option>
//    <option value="<a href="http://currencysource.com/RSS/MUR.xml%22%3EMauritian">http://currencysource.com/RSS/MUR.xml">Mauritian</a> Rupee</option>
//    <option value="<a href="http://currencysource.com/RSS/MXN.xml%22%3EMexican">http://currencysource.com/RSS/MXN.xml">Mexican</a> Peso</option>
//    <option value="<a href="http://currencysource.com/RSS/NPR.xml%22%3ENepalese">http://currencysource.com/RSS/NPR.xml">Nepalese</a> Rupee</option>
//    <option value="<a href="http://currencysource.com/RSS/NZD.xml%22%3ENew">http://currencysource.com/RSS/NZD.xml">New</a> Zealand Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/NOK.xml%22%3ENorwegian">http://currencysource.com/RSS/NOK.xml">Norwegian</a> Krone</option>
//    <option value="<a href="http://currencysource.com/RSS/OMR.xml%22%3EOmani">http://currencysource.com/RSS/OMR.xml">Omani</a> Rial</option>
//    <option value="<a href="http://currencysource.com/RSS/PKR.xml%22%3EPakistan">http://currencysource.com/RSS/PKR.xml">Pakistan</a> Rupee</option>
//    <option value="<a href="http://currencysource.com/RSS/PLN.xml%22%3EPolish">http://currencysource.com/RSS/PLN.xml">Polish</a> Zloty</option>
//    <option value="<a href="http://currencysource.com/RSS/GBP.xml%22%3EPound">http://currencysource.com/RSS/GBP.xml">Pound</a> Sterling</option>
//    <option value="<a href="http://currencysource.com/RSS/QAR.xml%22%3EQatar">http://currencysource.com/RSS/QAR.xml">Qatar</a> Riyal</option>
//    <option value="<a href="http://currencysource.com/RSS/SAR.xml%22%3ESaudi">http://currencysource.com/RSS/SAR.xml">Saudi</a> Arabian Riyal</option>
//    <option value="<a href="http://currencysource.com/RSS/SGD.xml%22%3ESingapore">http://currencysource.com/RSS/SGD.xml">Singapore</a> Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/SIT.xml%22%3ESlovenian">http://currencysource.com/RSS/SIT.xml">Slovenian</a> Tolar</option>
//    <option value="<a href="http://currencysource.com/RSS/ZAR.xml%22%3ESouth">http://currencysource.com/RSS/ZAR.xml">South</a> African Rand</option>
//    <option value="<a href="http://currencysource.com/RSS/LKR.xml%22%3ESri">http://currencysource.com/RSS/LKR.xml">Sri</a> Lanka Rupee</option>
//    <option value="<a href="http://currencysource.com/RSS/SEK.xml%22%3ESwedish">http://currencysource.com/RSS/SEK.xml">Swedish</a> Krona</option>
//    <option value="<a href="http://currencysource.com/RSS/SEK.xml%22%3ESwiss">http://currencysource.com/RSS/SEK.xml">Swiss</a> Franc</option>
//    <option value="<a href="http://currencysource.com/RSS/THB.xml%22%3EThai">http://currencysource.com/RSS/THB.xml">Thai</a> Baht</option>
//    <option value="<a href="http://currencysource.com/RSS/TTD.xml%22%3ETrinidad">http://currencysource.com/RSS/TTD.xml">Trinidad</a> & Tobago Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/AED.xml%22%3EU.A.E">http://currencysource.com/RSS/AED.xml">U.A.E</a>. Dirham</option>
//    <option value="<a href="http://currencysource.com/RSS/USD.xml%22%3EU.S">http://currencysource.com/RSS/USD.xml">U.S</a>. Dollar</option>
//    <option value="<a href="http://currencysource.com/RSS/VEB.xml%22%3EVenezuelan">http://currencysource.com/RSS/VEB.xml">Venezuelan</a> 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

About the Author

Suvendu Banik
Program Manager
India India
Love to code

Comments and Discussions

 
GeneralRSS Feeds now require a password Pinmemberstapes22-Feb-11 3:24 
GeneralDoesn't work Pinmemberstapes22-Feb-11 3:17 
GeneralOld exchange rates PinmemberZahid Rasool31-Oct-08 10:03 
GeneralGood information Pinmemberfriendz4u12-Jul-07 0:03 
Jokeugh PinmemberMatthew Hazlett25-Jun-07 18:37 
Generalcomment PinmemberRepliCrux20-Jun-07 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 21 Jun 2007
Article Copyright 2007 by Suvendu Banik
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid