-One DropDownList的货币转换器​​ - [英] -One dropdownlist currency converter-

查看:194
本文介绍了-One DropDownList的货币转换器​​ - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用一个DropDownList的将其转换为我的速度字段转换。例如,如果日本选择DropDownList的,当用户选择和改变马来西亚的速度字段将自动更改为从日本利率马来西亚速率。有人吗?...谢谢...

I wanted to convert my rate field by using one dropdownlist to convert it. Eg, if the dropdownlist selected on japan, when the user select and change to malaysia the rate field will automatically change to malaysia rate from japan rate. Anyone?... Thanks...

推荐答案

下拉列表中有两个值 - 文本和值。你或者你的约束下拉列表中一组项目(可能在​​一个IEnumerable像一个数组或列表)。因此,所有你所要做的就是拦截在客户端onchange事件,抢在下拉列表中选择的值,并将其放置到标签/文本框,显示的速度。下面是一个例子:

Dropdown lists have two values - the text and the value. You have either bound your dropdown list to a set of items (probably in an IEnumerable like an array or List). So all you have to do is intercept the onchange event on the client side, grab the selected value of the dropdown, and place it into the label/textbox that shows the rate. Here is an example for you:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" onchange="javascript:PopulateRate(this.value);"></asp:DropDownList>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" onchange="javascript:SelectRate(this.value);" style="width: 100px;"></asp:TextBox>
    </div>
    </form>
</body>

    <script language="javascript">
        function PopulateRate(value) {
            //debugger;
            document.getElementById('<% =Label1Name() %>').innerText = value;
        }
        function SelectRate(value) {
            var z = document.getElementById('<% =DropDownList1Name() %>');
            //method 1 to set dropdown selected item:
            z.value = value;
            //method 2 to set dropdown selected item::
            for (var i = 0; i < z.options.length; i++) {
                if (z.options[i].value == value) {
                    z.options[i].selected = true;
                    return;
                }
            } 
        }
    </script>

</html>


Partial Class _Default
Inherits System.Web.UI.Page

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)

    Dim countryRates = New System.Collections.Generic.Dictionary(Of String, Decimal)

    countryRates.Add("Japan", 1.0)
    countryRates.Add("Malaysia", 1.5)
    countryRates.Add("Khazakstan", 1.75)
    countryRates.Add("Argentina", 2.0)
    countryRates.Add("Andorra", 2.5)

    DropDownList1.DataTextField = "Key"
    DropDownList1.DataValueField = "value"
    DropDownList1.DataSource = countryRates
    DropDownList1.DataBind()
End Sub

Protected Property Label1Name() As String
    Get
        Return Label1.UniqueID
    End Get
    Set(ByVal value As String)

    End Set
End Property
Protected Property DropDownList1Name() As String
    Get
        Return DropDownList1.UniqueID
    End Get
    Set(ByVal value As String)

    End Set
End Property
End Class

从你的描述,这显示了如何做你想要的。我只是想让你知道,它伤害了我的头在VB.Net这样做样本:)(所以你必须原谅我伪劣VB code,我通常做C#)

From your description, this shows how to do what you want. I just want you to know that it hurt my head to have to do this sample in VB.Net :) (so you will have to excuse my shoddy VB code, i usually do C#)

这篇关于-One DropDownList的货币转换器​​ - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆