日期:2014-05-18  浏览次数:20359 次

asp.net自定义一个控件 可输入的下拉框
我想自定义一个控件。可输入的下拉框。但是不太会定义啊。 环境vs2008

 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

<span style="width:18px;border:0px solid red; position:relative; ">
  <asp:DropDownList ID="DropDownList1" runat="server" ></asp:DropDownList>
</span>
 
还要对span设置样式。我都不会。希望各位大侠 指点一下呀

------解决方案--------------------
网上有现成的
http://www.obout.com/combobox/

也可以搜索google asp.net combox control
------解决方案--------------------
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx
------解决方案--------------------
参考(第二个搜索功能):
http://www.cnblogs.com/insus/archive/2011/11/25/2263185.html
------解决方案--------------------
路过,帮顶下
------解决方案--------------------
我这有个 代码是
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ex060
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (comboBox1.Text != "")
            //{
            //   string newItem=comboBox1.Text.Trim(); 
            //    for (int i = 0; i < comboBox1.Items.Count; i++)
            //    {
            //        if (string.Compare(newItem, comboBox1.Items[i].ToString()) == 1)
            //        {
            //            MessageBox.Show("组合框中已有相同项,不能再添加!");
            //            return;
            //        }
            //        else
            //            comboBox1.Items.Add(comboBox1.Text.Trim());

            //    }
                    
            //}
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text != "")
            {
                string newItem = comboBox1.Text.Trim();//获取输入文本
                bool flag = false;//标识变量
                for (int i = 0; i < comboBox1.Items.Count; i++)
                {
                  //判断是否有相同项
                    if (string.Compare(newItem, comboBox1.Items[i].ToString()) == 0)
                    {
                        flag = true;
                        MessageBox.Show("已经有相同项,不能再添加");

                    }
                   
                }
                if (flag == false)
                { 
                
                  comboBox1.Items.Add(newItem);//将输入文本添加到项中
                  comboBox1.Text = "";

                }

            }

        }
    }
}

------解决方案--------------------
这个 是设计界面代码

C# code

namespace Ex060
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();