2010-02-01 2 views
0

하나의 드롭 다운 목록을 사용하여 환율 필드를 변환하려고했습니다. 예를 들어 일본에서 드롭 다운 목록을 선택한 경우 사용자가 말레이시아를 선택하여 말레이시아로 변경하면 비율 필드가 자동으로 일본 비율의 말레이시아 요금으로 변경됩니다. 누구 ...? 감사 ...- 하나의 드롭 다운 목록 통화 변환기 -

+0

프로그래밍 언어를 지정하십시오. – SingleShot

+0

* 모든 코드가 있습니까? –

+0

asp.net VB 언어, 아니요 .. 코드가 없습니다 – tohru

답변

1

드롭 다운 목록에는 텍스트와 값의 두 가지 값이 있습니다. 드롭 다운 목록을 항목 집합 (아마도 배열 또는 목록과 같은 IEnumerable에 있음)에 바인딩했습니다. 따라서 클라이언트 측에서 onchange 이벤트를 가로 채고 드롭 다운의 선택된 값을 잡고 비율을 나타내는 레이블/텍스트 상자에 배치하면됩니다. 다음은 귀하를위한 예입니다.

<%@ 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 코드를 변명해야한다. 보통은 C#을 사용한다.)

+0

감사합니다. =) 괜찮습니다 ... = D – tohru

+0

ohya, 내가 물어보고 싶은 것은 레이블 비율을 얻을 수 있습니까? 선택한 드롭 다운 목록으로 변환하십시오 ... – tohru

+0

가능합니다. 텍스트 상자에 값을 입력하고 드롭 다운에서 해당 값을 멀리 떨어 뜨리면 텍스트 상자가 포함 된 수정 된 게시물을 선택하는 것이 가능합니다. – slugster