简体   繁体   English

输入类型 <select>在ASP.NET和C#中使用搜索文本框

[英]Input type <select> with search textbox in ASP.NET and C#

I want to implement this kind of <select> in ASP.NET. 我想在ASP.NET中实现这种<select>

What I want is to have a search text box like here when I click the <select> like in this link just put any login details. 我想要的是有一个搜索文本框,当我单击此链接中<select> ,只需输入所有登录详细信息即可。

I have this code working in PHP with jQuery and CSS. 我在jQuery和CSS的PHP中使用此代码。 But I don't know where or how can I implement this in ASP.NET. 但是我不知道如何在ASP.NET中实现它。 I tried copying the codes but it didn't work for dynamic contents. 我尝试复制代码,但不适用于动态内容。

Update: 更新:

Here's the html code without script whatsoever: 这是不带脚本的html代码:

<select name="blogpost-category" id="blogpost-category" class="required chzn-done"> 
   <option></option>
   <option>Lorem Ipsum</option>
   <option>Consetetur Sadipscing</option> 
   <option>Eirmod Tempor</option>
</select>

Please take note that the name , id and class in ASP.NET can be declared or include in code behind and the ID 's are system generated. 请注意,可以在ASP.NET中声明nameidclass ,或将其包含在后面的代码中,并且ID由系统生成。 What I'm trying to say is that when I set the value of ID in C# like this: 我要说的是,当我像这样在C#中设置ID的值时:

<asp:DropDownList ID="ddlCategory" runat="server" />

OR 要么

<asp:DropDownList ID="blogpost-category" runat="server" />

and binding the data using this C# script: 并使用以下C#脚本绑定数据:

    Dictionary<string,string> dict = new Dictionary<string,string>();
    DataTable dt = FillData(SQL_SELECT);

    dict.Add(string.Empty, string.Empty);
    dict.Add(def.ADDNEW, def.ADDNEW);

    foreach (DataRow dr in dt.Rows)
    {
        dict.Add(dr.ItemArray[def.ID].ToString(), dr.ItemArray[def.NAME].ToString());
    }//foreach

    ddlCategory.DataSource = dict;
    ddlCategory.DataValueField = def.KEY;
    ddlCategory.DataTextField = def.VALUE;
    ddlCategory.DataBind();

the result ID for both would be: 两者的结果ID为:

ctl00_ContentPlaceHolder1_ddlCategory and ctl00_ContentPlaceHolder1_blogpost-category repectively. ctl00_ContentPlaceHolder1_ddlCategoryctl00_ContentPlaceHolder1_blogpost-category

Thank you in advance. 先感谢您。

<asp:DropDownList id="blogpost-category" runat="server"
     DataSource="<% databindingexpression %>"
     DataTextField="Model.description"
     DataValueField="Model.id"
     AutoPostBack="True|False">

     <asp:ListItem value="value" selected="True|False">
          Text
     </asp:ListItem>

 </asp:DropDownList>

Have you tried it like this, bind the datasource (the collection that needs to be displayed, datatextfield is the text that will be displayed, datavaluefield the id 您是否尝试过像这样,绑定数据源(需要显示的集合,datatextfield是将要显示的文本,datavaluefield是id

Yes, you can make that with ASP.NET also. 是的,您也可以使用ASP.NET。 Firstly you need to get the things with "Web User Controls" in ASP.NET and then continue with that.. :) 首先,您需要在ASP.NET中使用“ Web用户控件”来获取内容,然后继续执行.. :)

Happy coding.. :) 快乐的编码.. :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM