如何从选定的下拉列表值中填充两个文本框 [英] How to fill two text boxes from selected dropdownlist value

查看:82
本文介绍了如何从选定的下拉列表值中填充两个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框和一个下拉列表。



在下拉列表中数据是

iphone4-12000

iphone4s-12500



喜欢这个......



选择iphone4- 12000我希望在两个文本框中显示..



一个文本框iphon4(名称)



另一个文本框12000 (价格)



我尝试过:



i have two text boxes and one drop down list.

In drop down lists data's are
iphone4-12000
iphone4s-12500

like this....

when select iphone4-12000 i want display in two textboxes..

one textbox iphon4(name)

another textbox 12000(price)

What I have tried:

<asp:DropDownList  ID="DropDownList1" runat="server">
                  <asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">Iphone4</asp:ListItem>
<asp:ListItem Value="2">Iphone4s</asp:ListItem>
<asp:ListItem Value="3">Iphone5</asp:ListItem>
<asp:ListItem Value="4">Iphone5s</asp:ListItem>
<asp:ListItem Value="5">Iphone6</asp:ListItem>
<asp:ListItem Value="6">Iphone6s</asp:ListItem>
<asp:ListItem Value="7">Iphone7</asp:ListItem>
<asp:ListItem Value="8">Iphone 7 Plus</asp:ListItem>


                </asp:DropDownList>

推荐答案

Google搜索是您的朋友:< a href =https://www.google.com.au/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#safe=off&q=c%23+asp。 net + How + to + fill + text + box + from + selected + dropdownlist + value& *> c#asp.net如何填写所选下拉列表值的文本框 - Google [ ^ ]
Google search is your friend: c# asp.net How to fill text box from selected dropdownlist value - Google[^]


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
           string text  = DropDownList1.SelectedItem.Text;
           string[] parts = text.Split('-');
           if (parts.Length == 2)
           {
               TextBox1.Text = parts[0];
               TextBox2.Text = parts[1];
           }

        }





使用Javascript





Using Javascript

<asp:DropDownList ID="DropDownList1" onchange="setvalues(this)" runat="server">
            <asp:ListItem Value="0">--Select--</asp:ListItem>
            <asp:ListItem Value="1">Iphone4-3333</asp:ListItem>
            <asp:ListItem Value="2">Iphone4s-43434</asp:ListItem>
            <asp:ListItem Value="3">Iphone5-454545</asp:ListItem>
            
        </asp:DropDownList>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>




function setvalues(obj)
        {
            var text = obj.options[obj.selectedIndex].text;
            var parts = text.split('-');
            document.getElementById('<%= txtName.ClientID %>').value = parts[0];
            document.getElementById('<%= txtPrice.ClientID %>').value = parts[1];

        }


这篇关于如何从选定的下拉列表值中填充两个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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