如何根据文本框显示下拉列表中的值 [英] How show value in dropdown based on textbox

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

问题描述

我想在文本框中键入一些文本,基于该文本框值下拉列表值应该是select.in我的下拉值来自数据库。

请帮助我。给我逻辑



我尝试过:



i试图使用ajax使用dropdownlistextender但不是工作

i want to type some text in textbox based on that text box value dropdownlist value should be select.in my dropdown values are coming from database.
please help me.give me logic

What I have tried:

i have tried to use dropdownlistextender using ajax but not working

推荐答案

我还没有从你发布的句子中清楚地理解。如果你想根据文本框中输入的文本选择下拉列表项,在asp.net webform中你可以使用textchanged event。

代码看起来像这样

I have not clearly understood from sentence you posted.if you want to select dropdownlist item based on text entered on textbox ,in asp.net webform you can use textchanged event.
Code will look something like this
protected void TextBox1_TextChanged(object sender, EventArgs e)
      {
          if (TextBox1.Text == "xyz")
              DropDownList1.SelectedValue = "0";
      }


aspx中的
类似这样的东西。


in aspx something like this\..

<div>
        <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
    
    </div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>



如果要停止,可以使用更新面板回发


you can use update panel if you want to stop postback


尝试使用javascript



try this using javascript

<html>
<head>
    <script>
        function selectValue(e, value) {
            var ddl = document.getElementById('<%= DropDownList1.ClientID %>');
            for (var i = 0; i < ddl.options.length; i++) {
                if (ddl.options[i].text == value) {
                    ddl.options[i].selected = true;
                }
            }
        }
    </script>

</head>
<body>

    <form id="form1" runat="server">

        <asp:TextBox ID="TextBox1" onkeyup="selectValue(event,value)" runat="server"></asp:TextBox>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </form>

</body>
</html>


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

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