1)Right click on the project
2)click add web reference
3)copy below url in the url field:
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
Click on go button
Detail of currency convertion will be displayed below the textbox
give the name : "CurrencyConverter" in the reference text box.
click on the add reference
code on design view :
<div>
<asp:TextBox runat="server" ID="TextBoxRes"></asp:TextBox>
<asp:DropDownList runat="server" ID="drpFromCurrency"></asp:DropDownList>
<asp:DropDownList runat="server" ID="drpToCurrency"></asp:DropDownList>
<asp:Button runat="server" ID="btnConvert" Text="Convert" OnClick="Convert_Click" />
</div>
<asp:TextBox runat="server" ID="TextBoxRes"></asp:TextBox>
<asp:DropDownList runat="server" ID="drpFromCurrency"></asp:DropDownList>
<asp:DropDownList runat="server" ID="drpToCurrency"></asp:DropDownList>
<asp:Button runat="server" ID="btnConvert" Text="Convert" OnClick="Convert_Click" />
</div>
Code behind :
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
CurrencyConverter.Currency cur = new CurrencyConverter.Currency();
Array arr;
arr = System.Enum.GetValues(cur.GetType());
drpFromCurrency.DataSource = arr;
drpFromCurrency.DataBind();
drpToCurrency.DataSource = arr;
drpToCurrency.DataBind();
}
}
protected void Convert_Click(object sender, EventArgs e)
{
CurrencyConverter.CurrencyConvertor obj = new CurrencyConverter.CurrencyConvertor();
CurrencyConverter.Currency Currency = new CurrencyConverter.Currency();
double dt = new double();
dt = obj.ConversionRate((CurrencyConverter.Currency)System.Enum.Parse(Currency.GetType(), drpFromCurrency.Text), (CurrencyConverter.Currency)System.Enum.Parse(Currency.GetType(), drpToCurrency.Text));
TextBoxRes.Text = Convert.ToString(dt * Convert.ToDouble(TextBoxRes.Text));
}
"CurrencyConverter.CurrencyConvertor obj = new CurrencyConverter.CurrencyConvertor();" this line of code is givving me problems because CurrencyConverter.CurrencyConvertor cannot be found. Do you know what can be the problem please??
ReplyDeletejust edit the web reference name as CurrencyConventor
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood Example...
ReplyDeleteThis works without any error when you add as Web Reference instead of Service Reference (Go to Add Service Reference and then choose Advanced and then Web Reference)
I have 3 items in 2 combobox each:
ReplyDeleteFromBox.Items.Add("SGD");
FromBox.Items.Add("USD");
FromBox.Items.Add("EUR");
ToBox.Items.Add("SGD");
ToBox.Items.Add("USD");
ToBox.Items.Add("EUR");
How do i link these with the web reference to get the updated currency rates ?