0

現在のすべてのジョブ番号を表示するドロップダウン リストがあります。この番号に相当する「名前」を表示するテキスト ボックスが必要です。ドロップダウン リストは、同じデータベース内の別のテーブルへのクエリに基づいています。ドロップダウン リストは次のとおりです。

<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref" 
     DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute; 
     width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True">
</asp:DropDownList>

私がする必要があるのは、この select Name from ActiveJobs where Ref = dlRef.DataValueField.

これは可能ですか、またはこの情報を表示するために別の構造を使用する必要がありますか?

4

2 に答える 2

0

次の機能を使用できます

onchange="showText(this.options[this.selectedIndex].text);"

ドロップダウンに追加すると、

<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref" 
     DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute; 
     width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True"
      onchange="showText(this.options[this.selectedIndex].text);">
</asp:DropDownList>

JavaScript で関数を作成する

function showText(value)
{
   document.getElementById("textboxid").value=value
}

編集 1

<head>
    <title>DropDown</title>
    <script type="text/javascript">
    function chkind(){
    var dropdown1 = document.getElementById('dlRef');
    var textbox = document.getElementById('textbox');
    var a = dropdown1.options[dropdown1.selectedIndex].text;
    textbox.value = a;

    }
    }
    </script>
</head>

<body>
<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref" 
 DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute; 
 width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True"
 onchange="chkind()">
    <option>Hi</option>
    <option>Bye</option>
</select><br />
<asp:textbox id="textbox" type="text" runat="server" />
</body>
于 2013-02-25T16:19:28.073 に答える
0

これを行うにはJavaScriptを使用します。を追加しonchange=functionName()asp:DropDownListjavascript で onchange を処理して、テキスト ボックスのテキストをドロップダウン リストの値に変更します。

編集:

次のように onchange イベントを呼び出すことができます。

<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref" 
     DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute; 
     width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True" onchange="changeTextBox(this)">
</asp:DropDownList>

そして、あなたのスクリプトは次のようになります:

<script>
    function changeTextBox(data) {
        document.getElementById("yourTextBoxId").value = data.value;
    }
</script>

テキストを表示したい場合は、 text プロパティを使用する必要があると思います。

注: html5 の時点では、script タグは type 属性なしでそのまま使用できます。

于 2013-02-25T15:51:59.393 に答える