如何在网站c#中创建一个ComboBox

时间:2016-02-03 10:52:43

标签: c# asp.net drop-down-menu combobox

我使用visual studio 2015在c#中创建了一个网站。我希望我有一个DropDownList,它让我可以在文本区写入,就像在TextBox中写一样。我发现应该是一个ComboBox但是我在visual studio 2015中我的ToolBox中找不到thic组件.. 这是我的DropDownList的代码:

<asp:Label ID="Label4" text="Lastname :" runat="server"  ForeColor="#80FF00"></asp:Label><br />
        <asp:DropDownList ID="DropDownList1" runat="server"  Enabled="true"  Width="140px"  AutoPostBack="false"></asp:DropDownList>

2 个答案:

答案 0 :(得分:0)

您可以浏览以下链接,它有效: 下载项目(链接)并将dll,css,Js,image添加到项目中。

http://www.codeproject.com/Articles/290218/Custom-ASP-NET-Editable-DropDownList

我使用的代码下面,它的工作原理。

  protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {

        DataSet ds = new DataSet();
        DataTable dtFields = new DataTable();
        dtFields.Columns.Add("Id", typeof(int));
        dtFields.Columns.Add("FName", typeof(string));

        dtFields.Rows.Add(1, "UserName");
        dtFields.Rows.Add(2, "Password");
        dtFields.Rows.Add(3, "Login");
        EditableDropDownList1.DataSource = dtFields;
        EditableDropDownList1.DataTextField = "FName";
        EditableDropDownList1.DataValueField = "Id";
        EditableDropDownList1.DataBind();

        EditableDropDownList1.Items.Insert(0,"--select--");
    }
}
     <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs"    Inherits="Index" %>
      <%@ Register Assembly="EditableDropDownList" 
      Namespace="EditableControls" TagPrefix="editable" %> 
      <!DOCTYPE html>

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
<title></title>
<link href="css/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.core.js" type="text/javascript"></script>
<script src="js/jquery.ui.widget.js" type="text/javascript"></script>
<script src="js/jquery.ui.button.js" type="text/javascript"></script>
<script src="js/jquery.ui.position.js" type="text/javascript"></script>
<script src="js/jquery.ui.autocomplete.js" type="text/javascript"></script> 
<script src="js/jquery.ui.combobox.js" type="text/javascript"></script> 
       </head>
       <body>
        <form id="form1" runat="server">
        <div>
       <asp:Label ID="Label4" text="Lastname :" runat="server"          ForeColor="#80FF00"></asp:Label><br />
       <editable:EditableDropDownList ID="EditableDropDownList1" runat="server"> 
       </editable:EditableDropDownList> 
           </div>
          </form>
          </body>
       </html>

答案 1 :(得分:-3)

在文本框中获取此类功能的最简单方法是

  <input type="text" list="languages" id="txtLang" runat="server" >
            <datalist id="languages">
                <option value="HTML">
                    <option value="CSS">
                        <option value="JavaScript">
                            <option value="Java">
                                <option value="Ruby">
                                    <option value="PHP">
                                        <option value="Go">
                                            <option value="Erlang">
                                                <option value="Python">
                                                    <option value="C">
                                                        <option value="C#">
                                                            <option value="C++">
            </datalist>

在上面的datalist中你也可以从数据库中加载自己的数据